Back to Blog

Automate Your Mac with Script Snippets: JavaScript and AppleScript

April 8, 2026by TypeFire
applescript text expanderjavascript snippets macmac automation

Text expansion typically means typing a short abbreviation and getting static text back. TypeFire goes further with script snippets - snippets that execute JavaScript or AppleScript and insert the result. Instead of expanding pre-written text, you are running code that generates content on the fly.

This opens up a different category of automation entirely. Generate UUIDs, calculate dates, transform clipboard content, query system information, format data, or interact with macOS APIs - all triggered by a simple abbreviation or the launcher.

Automate Your Mac with Script Snippets: JavaScript and AppleScript

How Script Snippets Work

When you create a snippet in TypeFire, you can select "Script" as the content type. You then choose either JavaScript or AppleScript and write your code in the editor.

When you trigger the snippet (via abbreviation, keyboard shortcut, or the launcher), TypeFire:

  1. Executes your script
  2. Captures the output (the return value)
  3. Inserts the output as text into your active application

The script runs locally on your Mac. Nothing is sent to any server. Execution is nearly instant for most scripts.

JavaScript Snippet Examples

JavaScript is the most versatile option for script snippets. Here are practical examples:

Generate a UUID

Abbreviation: ;uuid

function generateUUID() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0;
    var v = c === 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}
return generateUUID();

Every time you type ;uuid, you get a fresh, unique UUID. Invaluable for developers who need IDs in test data, configuration files, or documentation.

Unix Timestamp

Abbreviation: ;timestamp

return Math.floor(Date.now() / 1000).toString();

Returns the current Unix timestamp. Useful for logging, debugging, and API work.

ISO Date String

Abbreviation: ;isodate

return new Date().toISOString();

Outputs something like 2026-04-08T14:30:00.000Z. Standard format for APIs and databases.

Format a Date

Abbreviation: ;fdate

const d = new Date();
const months = ['January', 'February', 'March', 'April', 'May', 'June',
  'July', 'August', 'September', 'October', 'November', 'December'];
return `${months[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;

Outputs "April 8, 2026" - a fully written-out date format that {{date}} tokens might not cover.

Calculate Days Until a Date

Abbreviation: ;daysuntil

const target = new Date('2026-12-31');
const today = new Date();
const diff = Math.ceil((target - today) / (1000 * 60 * 60 * 24));
return `${diff} days until December 31, 2026`;

Modify the target date for project deadlines, launch dates, or personal milestones.

Random Password Generator

Abbreviation: ;randpass

const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%&*';
let result = '';
for (let i = 0; i < 20; i++) {
  result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;

Generates a 20-character random string. Useful for temporary passwords, test accounts, or placeholder tokens.

Transform Clipboard to Title Case

Abbreviation: ;titlecase

const text = "{{clipboard}}";
return text.replace(/\w\S*/g, function(txt) {
  return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});

Copy text, type ;titlecase, and the clipboard content expands in Title Case format.

JSON Formatter

Abbreviation: ;jsonformat

try {
  const json = JSON.parse("{{clipboard}}");
  return JSON.stringify(json, null, 2);
} catch(e) {
  return "Invalid JSON on clipboard";
}

Copy minified JSON, type ;jsonformat, and get pretty-printed output. Every developer needs this.

Word Count

Abbreviation: ;wcount

const text = "{{clipboard}}";
const words = text.trim().split(/\s+/).length;
const chars = text.length;
return `Words: ${words} | Characters: ${chars}`;

Copy a block of text, expand this snippet, and get an instant word and character count.

AppleScript Snippet Examples

AppleScript gives you access to macOS system APIs and native applications. This is where script snippets become truly powerful for Mac-specific automation.

Get Current Finder Path

Abbreviation: ;finderpath

tell application "Finder"
  set currentPath to POSIX path of (target of front window as text)
end tell
return currentPath

Inserts the file path of whatever folder is open in Finder. Great for documentation or terminal commands.

Get Current Safari URL

Abbreviation: ;safariurl

tell application "Safari"
  set currentURL to URL of current tab of front window
end tell
return currentURL

Instantly paste the URL of the page you are viewing in Safari. Works for link sharing, documentation, and bookmarking.

Get Frontmost App Name

Abbreviation: ;appname

tell application "System Events"
  set frontApp to name of first application process whose frontmost is true
end tell
return frontApp

Inserts the name of the active application. Useful in bug reports or workflow documentation.

System Information

Abbreviation: ;sysinfo

set compName to computer name of (system info)
set osVer to system version of (system info)
return "Computer: " & compName & " | macOS: " & osVer

Quick system details for IT tickets, bug reports, or documentation.

Get Selected Text from Any App

Abbreviation: ;selected

tell application "System Events"
  keystroke "c" using command down
  delay 0.1
end tell
return the clipboard

Captures the currently selected text. Useful as a building block for more complex scripts that need to act on your current selection.

Combining Scripts with Dynamic Tokens

Script snippets can use TypeFire's dynamic tokens. The {{clipboard}} token is especially powerful inside scripts because it lets you process clipboard content programmatically.

Encode URL (;urlencode):

return encodeURIComponent("{{clipboard}}");

Decode HTML entities (;htmldecode):

const text = "{{clipboard}}";
const entities = {"&amp;": "&", "&lt;": "<", "&gt;": ">", "&quot;": '"', "&#39;": "'"};
return text.replace(/&amp;|&lt;|&gt;|&quot;|&#39;/g, m => entities[m]);

Base64 encode (;b64encode):

return btoa("{{clipboard}}");

Base64 decode (;b64decode):

return atob("{{clipboard}}");

These clipboard-processing scripts create a powerful workflow: copy content, trigger the script snippet, get the transformed result inserted instantly.

When to Use Scripts vs Static Snippets

Use static snippets when:

  • The content is always the same (templates, boilerplate, signatures)
  • You need rich text formatting or Markdown
  • Speed is critical (static expansion is slightly faster than script execution)

Use script snippets when:

  • The output needs to be different every time (UUIDs, timestamps, random values)
  • You need to transform input (clipboard processing, format conversion)
  • You want to interact with macOS or applications (Finder paths, browser URLs)
  • You need calculations (dates, counters, metrics)

Safety and Permissions

Script snippets run locally with your user permissions. A few things to keep in mind:

  • JavaScript runs in a sandboxed context - It cannot access your file system or network directly
  • AppleScript has broader access - It can interact with applications and system APIs, so it may trigger macOS permission dialogs the first time
  • No network calls - Scripts are designed for local computation and system interaction, not for making API calls

TypeFire does not send your scripts to any external server. Everything executes on your machine.

Getting Started with Script Snippets

Start with the simple ones - a UUID generator, a timestamp, or a date formatter. These require no setup and provide immediate value. Once you are comfortable with the concept, experiment with clipboard-transforming scripts and AppleScript integrations.

The combination of text expansion triggers (abbreviations, shortcuts, launcher) with script execution makes TypeFire more than a text expander - it becomes a lightweight automation platform that runs from any text field on your Mac. And like everything else in TypeFire, script snippets are completely free.

Store and manage your snippets with TypeFire

Free text expander for Mac. Type abbreviations, they expand instantly in any app.

Download for macOS