I just wanted to share one of the coolest things about TextExpander that I didn’t expect when I first started using it: the ability to write and execute JavaScript snippets. I use it super often, and one of my go-to snippets is a UUID v4 generator.
Just change the type of the Snippet to JavaScript and fill the content with this block:
function generateUUID() { // Public Domain/MIT
var d = new Date().getTime();//Timestamp
var d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now()*1000)) || 0;//Time in microseconds since page-load or 0 if unsupported
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16;//random number between 0 and 16
if(d > 0){//Use timestamp until depleted
r = (d + r)%16 | 0;
d = Math.floor(d/16);
} else {//Use microseconds since page-load if supported
r = (d2 + r)%16 | 0;
d2 = Math.floor(d2/16);
}
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
}
generateUUID().toUpperCase();
When you expand it, the result is going to be a v4 UUID such as this one: 30DF0014-8E23-4C67-BA1D-731CCE255EEB
Anyone else using JavaScript or other creative techniques in your snippets? I’d love to hear about your favorite hacks or any improvements you’ve made! Your Most Surprising Use for TextExpander?
I was talking to a teacher buddy of mine - and we played with TE snippets for common feedback on assignments. Because most gradebooks are online applications, you can use TE overtop of them - so, you can add a snippet for things like “This assignment was turned in blank” as just blank or “Test Retakes must be completed by March 1st in order to receive full marks” as just retake.
Any comment that a teacher is entering multiple times can be easily set up and applied with type commands, increasing the feedback that parents receive while maintaining a uniform policy AND keeping feedback time short.
Funny you mention that, Linda! My mom is a teacher and I promised to get her up and running on TextExpander for her report card comments this year. We’ll see how much time she saves after 30+ years of copying and pasting/rewriting common phrases. (I think it will be quite a lifesaver )
A couple of years ago, I interviewed a middle school teacher for the blog, and that’s exactly what he uses TextExpander for: Leaving feedback in Google Classroom. I should invite him in here.
I use the Accented Words public group all the time. It helps me with résumé, café, brûlée, and many others. It’s also how I learned that ångström has some cool accents. Indulge your inner “word nerd” with TextExpander.
Wow, I love seeing all the creative ways people are using TextExpander! One of my favorite surprising uses is leveraging JavaScript snippets to generate dynamic, customizable tables. If you need structured data formatted just right—whether for reports, logs, or documentation—this trick can save tons of time!
To get started, change the Content Type of your snippet to JavaScript and use this line to ensure TextExpander correctly parses the HTML:
TextExpander.expandHTML = true;
`
// your HTML content goes here
`;
From there, you can build your perfect table using an HTML editor. I personally like this one—just design your table, click “Edit HTML source code”, and paste the generated code into your snippet between those backticks.
Bonus Tip: You can also use this trick to load external images via a link inside your table! Just use a standard <img> tag in your HTML, like this:
This is super handy for creating snippets that include logos, product images, or reference graphics right inside your table!
Want a quick walkthrough? I recorded a short video to guide you through setting up these kinds of snippets—check it out here: https://share.zight.com/E0uNNDjy
The best part? Since it’s JavaScript, you can even add logic to auto-populate data, customize styles, or adjust formatting dynamically.
Has anyone else experimented with HTML + JavaScript snippets? Would love to hear what you’ve come up with!
For me, the most surprising snippets are the ones that use code. One in particular I use all the time converts an URL that has been copied (e.g., ⌘+L to go to the browser URL line, ⌘+C to copy it) and turns it into a TinyURL (shortened version of the URL). This makes emails much cleaner.
# a shortened link created by the tinyurl service
# So, to use it, copy and an URL then type your shortcurt, e.g. “ttiny”
# and it produces are shortened link using TinyURL
# www.WorkSmartAndBeRemarkble.com
set ClipURL to the clipboard
ignoring case
set curlCMD to ¬
"curl --stderr /dev/null \"http://tinyurl.com/api-create.php?url=" & ClipURL & "\""
-- Run the script and get the result:
set tinyURL to (do shell script curlCMD)
return tinyURL
end ignoring
Another scrip-based snippet I love is for getting a unique link to your last sent email. I use this, for example, in Omnifocus when I have email related to a task (“waiting for response from Bob” - adding link to email)
I wrote this up for an article for Asian Efficiency
The corresponding AppleScript is below.
# Helmut Hauser
# http://www.worksmartandberemarkable.com
#
# Jun 2015
# I wrote this up for an article for Asian Efficiency
# https://tinyurl.com/yxwjcfke
# You have to adapt this line to your mail account name
# You can find it in your Mail preferences under accounts and there in "Description"
set accountName to “Your Account Name"
tell application "Mail"
set _links to {}
set _msg to first message of mailbox "Sent" of account accountName
set _messageURL to "message://%3c" & _msg's message id & "%3e"
set end of _links to _messageURL
set AppleScript's text item delimiters to return
return (_links as string)
end tell
I’ve added two of the awesome Snippets from this thread to our Community Snippets Public Group. Subscribe to it, and then you can expand the Snippets with the prefix com.
This was originally an AppleScript that someone somewhere crafted for me, then TextExpander Support was kind enough to convert to JavaScript for me (I am not a coder).
It checks what time it is, then spits out “Good Morning/Afternoon/Evening” based on the time. I no longer need to check the clock before crafting an email or text.
The best part is that it works everywhere now, instead of just macOS.
var today = new Date();
var time = today.getHours();
if (time < 12) {
output ="Good morning"
} else if (time < 18) {
output ="Good afternoon"
} else {
output ="Good evening"
}
Controlling Spotify with Snippets is easily the most surprising use case I’ve seen. I can’t say I use these, and I’m more of an Apple Music guy, but they indeed work. Here’s the JavaScript:
Tell Spotify to play
var spotify = Application("Spotify");
spotify.play();
Pause Spotify
var spotify = Application("Spotify");
spotify.pause();
Expand the artist and title of the current song
var track = Application('Spotify').currentTrack()
let output = track.artist() + ' - ' + track.name()
output
I’ll let the more creative coders have fun with this concept!
I’ve created a snippet that translates the text in clipboard to another language using Google Translate API:
set endpoint to "https://translation.googleapis.com/language/translate/v2?key=YOUR-GOOGLE-API-KEY"
-- Get clipboard text
set textToTranslate to the clipboard
-- Remove single quotes from textToTranslate
set AppleScript's text item delimiters to "'"
set the textItems to text items of textToTranslate
set AppleScript's text item delimiters to ""
set textToTranslate to textItems as string
-- Make the API call using curl
set translatedText to do shell script "
curl -s -X POST '" & endpoint & "' \\
-H 'Content-Type: application/json' \\
-d '{
\"q\": \"" & textToTranslate & "\",
\"target\": \"pt-BR\"
}' | /opt/homebrew/bin/jq -r '.data.translations[0].translatedText'
"
return translatedText
Hey @AmandaEdson, I’m not a javascript expert, but I asked ChatGPT to convert the tiny URL snippet from applescript to javascript and here is what it returned:
Open TextExpander
Create a new snippet
Click the “Content” dropdown → choose JavaScript
Paste the script below
Set your abbreviation, e.g., ;shortenURL
Save and trigger it after copying a URL to your clipboard
ObjC.import('AppKit'); // Access the clipboard
// Get clipboard contents
var ClipURL = ObjC.unwrap($.NSPasteboard.generalPasteboard.stringForType($.NSPasteboardTypeString));
// Build and run curl command
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var curlCMD = `curl --stderr /dev/null "http://tinyurl.com/api-create.php?url=${ClipURL}"`;
var tinyURL = app.doShellScript(curlCMD);
// Output the shortened URL
tinyURL;
This appears to be working for me! Hope that’s helpful!
[quote=“Mike, post:20, topic:95”]
Hey @AmandaEdson, I’m not a javascript expert, but I asked ChatGPT to convert the tiny URL snippet from applescript to javascript and here is what it returned:
Open TextExpander
Create a new snippet
Click the “Content” dropdown → choose JavaScript
Paste the script below
Set your abbreviation, e.g., ;shortenURL
Save and trigger it after copying a URL to your clipboard
ObjC.import('AppKit'); // Access the clipboard
// Get clipboard contents
var ClipURL = ObjC.unwrap($.NSPasteboard.generalPasteboard.stringForType($.NSPasteboardTypeString));
// Build and run curl command
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var curlCMD = `curl --stderr /dev/null "http://tinyurl.com/api-create.php?url=${ClipURL}"`;
var tinyURL = app.doShellScript(curlCMD);
// Output the shortened URL
tinyURL;
This appears to be working for me! Hope that’s helpful!
Yay thank you! I will try that next time I see a script I like. I see a lot of Mac code
Thank you for this idea! I was able to take this and edit it to use weekend as well keeping only the time bits. And using a separate similar script get it to change out the adjective as well so that my replies are less robotic when emailing the same person! Such a great idea!
This is your space to ask questions, find support, and share ideas with fellow TextExpander users and our product team. As a first step, take a moment to introduce yourself to the community.