The Smile Blog, With News, Tips, Photos and Other Stuff That Makes Us Smile

Sample JavaScripts for TextExpander 5.0 / TextExpander touch 3.5

Posted 05/28/2015 by Greg

TextExpander 5.0 and TextExpander 3.5 add support for JavaScript snippets. JavaScript includes a very nice math library, so in addition to having snippets which run on both OS X and iOS, there are a number of snippets which are easier to write. Here are some examples of snippets you can make by setting the Content: menu of a new snippet to JavaScript, and pasting the following into the editor:

Calculate Body Mass Index (BMI)

// Body Mass Index (BMI) from height and weight
var height = Number(%filltext:name=m:default=1.64:width=5%);// meters
var weight = Number(%filltext:name=kg:default=57.5:width=5%);// kilograms
"Body mass index for subject " + height.toFixed(2) + "m tall weighing " +
	weight.toFixed(2) + "kg is: " + Number(weight / (height * height)).toFixed(2);

Compute Hourly Rate Total

// Compute a charge by multiplying hours * hourly rate
var hours = Number(%filltext:name=Hours:default=1.5:width=5%);
var hourlyrate = Number(%filltext:name=Rate:default=30:width=5%);
"Billing for " + hours + " hours at $" + hourlyrate + " for a total of $"
	+ (hours * hourlyrate);

JavaScript snippets can include fill-ins. Here's a quick calculator which can evaluate any valid JavaScript expression:

Quick Calculator

// Quick Calculator -- enter a valid JavaScript expression
%filltext:name=equation:default=2 + 3%;

Here is a more elaborate fill-in example used to tally a survey:

Assess Depression on PHQ-9 Depression Scale

// Depression scale
TextExpander.appendOutput("PHQ-9 Depression scale\n" +
"In last 2 weeks, how often have you experienced:\n\n" +
"  (Score for each answer: 0-'not at all'  1-'several days' " +
"   2-'more than half the days'  3-'nearly every day')\n" +
"1- little interest or pleasure in activities? %fillpopup:name=1:default=0:1:2:3%\n" +
"2- feeling down, depressed, or hopeless? %fillpopup:name=2:default=0:1:2:3%\n" +
"3- trouble falling asleep, staying asleep, or sleeping too much? %fillpopup:name=3:default=0:1:2:3%\n" +
"4- feeling tired or having little energy? %fillpopup:name=4:default=0:1:2:3%\n" +
"5- poor appetite or overeating? %fillpopup:name=5:default=0:1:2:3%\n" +
"6- feeling bad about self, feeling failure, or let self or others down? %fillpopup:name=6:default=0:1:2:3%\n" +
"7- trouble concentrating, reading newspaper, or TV? %fillpopup:name=7:default=0:1:2:3%\n" +
"8- moving or speaking so slowly that other people could have noticed? Or the opposite, being so fidgety or restless that you have been moving around a lot more than usual? %fillpopup:name=8:default=0:1:2:3%\n" +
"9- thoughts that you would be better off dead or of hurting yourself in some way? %fillpopup:name=9:default=0:1:2:3%\n\n");

var count = 0;
var sum = 0;
for (count = 1; count <= 9; count++) {
    var fieldVal = Number(TextExpander.filledValues["" + count]);
    if (fieldVal != NaN) {
        sum += fieldVal;
    else break;

TextExpander.appendOutput("Total: " + sum + "\n" +
	"   Greater than 10 => major depression\n" +
	"   Greater than 20 => severe depression\n");

Have a favorite JavaScript? Send it in and include permission so we can share it.

TextExpander Adds JavaScript Support

Posted 05/27/2015 by Greg

TextExpander 5 and TextExpander touch 3.5 now include support for standard JavaScript snippets, and TextExpander 5 also includes support for JavaScript for Automation on OS X.

As a basic example, a scientist with a frequent need for an approximation of Pi to eight digits of precision could set up a JavaScript snippet with abbreviation zpi and content:


Any time the user types zpi, it will expand to: 3.14159265.

Here is a more complex example. It's a TextExpander fill-in snippet which tells the user their zodiac sign:

zodiacSigns = ['monkey', 'rooster', 'dog', 'pig', 'rat', 'ox',
                'tiger', 'rabbit', 'dragon', 'snake', 'horse', 'goat'];
var index = %filltext:name=Enter your birth year:default=1984% % 12;
"Your Zodiac sign is the " + zodiacSigns[index] + ".\n";
// %filltop%

When expanded, the user is prompted for their birth date, and the snippet returns their zodiac sign. For example, if the user enters 1972, the snippet expands to "Your Zodiac sign is the rat."

Did you notice %filltop%? That tells TextExpander to duplicate any single line and popup fields at the top of the fill-in window and hide the script. You'll find that via the insert menu under Fill-ins > Show at top.

Content Object

TextExpander includes a JavaScript context object, which exposes the following items you might find useful. Precede these with TextExpander, for example, TextExpander.appendOutput("Hello, world!").

triggeringAbbreviation - the abbreviation which triggered the expansion [boolean, read/write]
ignoreOutput - do not use the final statement as the expansion [boolean, read/write]
appendOutput(text) - add text to the expansion [function]
baseDate - date and time at which the snippet is expanded [date, read only]
adjustedDate - date and time used to expand the snippet [date, read/write]
pasteboardText - clipboard contents [string, read/write]
expansionContext - bundle ID within which snippet is being expanded [string, read only; can be nil]
filledValues - fill-in field values [associative array of strings, read/write]

JavaScript for iOS and OS X

You can take advantage of JavaScript support on both OS X and iOS to create snippets which run on both platforms — something you can't do with AppleScripts and Shell Scripts. You can write a snippet to make the clipboard content lowercase in JavaScript like this:


JavaScript for Automation

On OS X, you can use JavaScript for Automation (JSA) as an alternative to AppleScript. This form of JavaScript will not function in iOS. TextExpander should automatically detect JSA, or you can force JavaScript to be treated as JSA by starting it with a comment: //JSA

Here is a JSA script to create a new message, set its subject, and set its content:

Mail = Application('Mail');
message = Mail.OutgoingMessage().make()
message.subject = "New Message";
message.content = "This is a new message created via JavaScript."

You might enjoy this article from MacStories on Getting Started with JavaScript for Automation.

If you have a favorite JavaScript, please send it in, and let us know if we can share it with the world.

TextExpander 5, featuring snippet suggestions

Posted 05/27/2015 by Team

We're excited to present TextExpander 5, featuring snippet suggestions.

TextExpander 5 suggests new snippets based on what you type the most, and reminds you when you miss a chance to use a snippet. That's time saved.

Sync with iCloud Drive, any Dropbox folder, or any syncing folder. (Details below.) Get improved search and JavaScript snippets among a host of other new features.



US $19.95 to upgrade from your current version. 

Free upgrades are available via the TextExpander 5 application to those who purchased version 4 on or after January 1, 2015.

Upgrade by downloading TextExpander 5. Launch it, and it will tell you if your upgrade is free or paid. If it's paid, click "Buy an upgrade license."

TextExpander 5 requires OS X 10.10 (Yosemite) or later.

What's New in Version 5:

  • Suggests snippets from phrases you habitually type
  • Reminds you of missed opportunities to use your abbreviations
  • Customize snippet file location
  • Sync via iCloud Drive or any sync folder
  • Simplified expansion of lengthy fill-ins and scripts
  • Search and expand snippets, abbreviations, and suggestions inline as you type
  • Preview expanded snippet
  • Refreshed statistics display
  • Supports JavaScript snippets that also operate on iOS
  • Updated for Mac OS X 10.10 Yosemite (required)


Setup New Sync:

Sync with any syncing folder.

  1. Open TextExpander to Preferences > Sync.
  2. Click Save Snippets As…
  3. Choose a location on your hard drive to store your snippets. If you choose a syncing folder, then your snippets will sync.

Update your other devices:

  1. On your second Mac open TextExpander to Preferences > Sync. On an iOS device open TextExpander's Settings to Sync Snippets.
  2. Click on Link To Snippets… 
  3. Locate your Settings.textexpandersettings file and select it. 

If you have an older version of TextExpander for Mac (4 or earlier) or TextExpander touch (3.2.4 or earlier), then you need to keep using the Older Version Dropbox sync by clicking Sync with TextExpander 4…

Setup Inline Search:

Can't remember snippets? Use search. It's more convenient to use than before.

  1. Open TextExpander to Preferences > Hotkey.
  2. Click the Click to Set Hotkey button next to Inline Search.
  3. Press your preferred hotkey combo. (Note: hotkey combinations must include Command, Option, Control and/or Shift plus any character or number key.)

Use the Inline Search :  

  1. Type your hotkey. The TextExpander search window will appear near your cursor.
  2. Type any part of your snippet, abbreviation, content, or label. Scroll through the results and click the one you want, or press Command + # for the option you want.

TextExpander touch 3.5: Sync with iCloud Drive, JavaScript snippets

Posted 05/26/2015 by Maia

TextExpander touch 3.5 is now available. Sync and store your snippets using any folder on Dropbox or iCloud Drive. We'll tell you how to set that up below.

Now you can search your snippets and abbreviations.

To update look in the Purchases tab of the App Store, tap Updates, then tap Update next to TextExpander 3.5.

TextExpander 5 for Mac is coming soon with support for the new Dropbox and iCloud Drive sync. Please update to TextExpander touch 3.5 to take full advantage of new sync options.

What's New in Version 3.5:

  • Sync snippets using iCloud Drive
  • Sync snippets using any Dropbox folder
  • Search snippets and abbreviations
  • Create JavaScript snippets
  • Other minor fixes and improvements

Setup New Sync:

  1. Open TextExpander's Settings and tap Sync Snippets.
  2. Click Save Snippets As… under iCloud Drive or Dropbox.
  3. Select a folder to store your snippets.

Make sure to update your other devices.

  1. On your second device open TextExpander's Settings to Sync Snippets.
  2. Tap on Link To Snippets… under Dropbox or iCloud Drive, whichever you used before.
  3. Locate your Settings.textexpandersettings file and select it. 

If you have an older version of TextExpander touch (3.2.4 or earlier), or TextExpander for Mac (4 or earlier), then you need to keep using the Older Version Dropbox sync.

TextExpander touch 3.5 Adds Create, Expand x-callback-url Support

Posted 05/26/2015 by Greg

Primarily of interest to other iOS app developers, in TextExpander touch 3.5 we've added create and expand commands to our x-callback-url support to allow other applications to work with TextExpander touch as part of a workflow.

Both of the new commands use the existing tetouch-xc URL callback scheme and standard x-callback-url conventions. To learn more about x-callback-urls in general, please visit

If you'd like to play with these calls before implementing them in your app, we recommend you download and build the XCallbackURL app. Screenshots for trying each call appear at the bottom of this post.


The create command allows third-party applications to create new snippets.
Command name = "create"


  • "abbr" - Abbreviation for snippet
  • "snippet" - Text to expand for snippet
  • "group" - (optional) Name of group to add the snippet to. Group must exist and be writeable. When not specified, the first writeable group is used.

x-success, no parameters, if created
x-error with error-Code, errorMessage, errorDomain (tctouch-xc-error) if not


   snippet=Let’s get lunch!&

(Note: callback URLs in parameters should be encoded. They were left decoded for legibility).


The expand command allows for expansion of an abbreviation. Command name = "expand"


  • "abbr" - Abbreviation to expand
  • "fillin" - (optional) Whether a fill-in snippet should prompt the user. Pass 0 to get back just the raw snippet. Default is 1 (user will fill-in)

x-success, expanded text in "expansion" parameter if expanded successfully
x-error, error-Code, errorMessage, errorDomain (tctouch-xc-error) if not



(Note: callback URLs in parameters should be encoded. They were left decoded for legibility).

x-callback-url create example    x-callback-url expand example

Smile at NCMUG

Posted 05/22/2015 by

Last week Smile got the chance to meet up with one of our favorite, and local, user groups, North Coast Mac User Group (NCMUG), located in California wine country.

We showed them how to be PDFpen power users, and showed off a few exciting sneak peaks of things to come.

Our history with NCMUG goes back to 2006, demoing at their Mac Computer Expo. You can see the original Smile Team demoing below, Jean, Greg, and Philip.

Jean, Greg, Philip

Didn't take any #SmileMugShots this time, but we did find a picture of the last time Smile and NCMUG were in the same room. Smile Team members Maia Olson and Kelly Guimont, NCMUG board members Ronnie Roche and Lorene Romero, and Former Smile-er and App Camp For Girls founder Jean MacDonald. They are relaxing after a 1 hour session for App Camp at last year's Macworld.

Girls on Stairs

2 Day Deal: PDFpen Scan+ 30% Off

Posted 05/20/2015 by Maia

Scan+PDFpen Scan+

2 Day Deal
30% off Thursday & Friday
Only on the App Store


Buy PDFpen Scan+, your scanning and OCR app for iPad and iPhone, on the App Store for $4.99 Thursday May 21st and Friday May 22nd. 

The power of your office in your pocket! Scan contracts, invoices, or receipts as PDFs with your iPhone® or iPad®. Use OCR (Optical Character Recognition) to make that scan into a searchable PDF! Watch it in action.

iPhone Scanning

Smileworthy: Podcasts

Posted 05/15/2015 by Maia

We love podcasts (mostly while commuting, or cooking dinner, or eating breakfast. Maybe while exercising? When do you consume podcasts, we wanna know?)

Such an entertaining, informative, and helpful part of the Mac community, we seek out new podcasts to listen to all the time. Sometimes we like them so much we sponsor them, as with all of the following.

If you’re in the mood to hear geeks of varying Mac stripes geek out, give these a listen.

PS. You do not have to be a geek to listen, but it helps to like your Apple hardware. In fact, all you really have to do is enjoy the show’s hosts. We’ll tell you who they are.

  1. Back to Work, over at the 5by5 network, is hosted by Merlin Mann and Dan Benjamin. Hear them talk (and talk and talk) about life, work, and everything, from the point of view of Mac productivity nerds.
  2. Bits Und So, our only German podcast, is hosted by Timo Hetzel and crew. They even have an iPhone app to make listening easier.
  3. Connected, over at, is hosted by Federico Viticci, Myke Hurley, and Stephen Hackett. The Italian, British, and American hosts offer their uniquely international views of the Apple universe with earnestness and good humor.
  4. Core Intuition is a favorite of a couple of the Smile Team. Hosts Daniel Jalkut and Manton Reece discuss the indie side of Apple’s various toys.
  5. The iMore Show, over at iMore, offers Apple gadget commentary from a panel of hosts, Rene Ritchie, Serenity Caldwell, Peter Cohen, and their guest of the week.
  6. The iOS Show is hosted by Michael Johnston, Adam Christianson (also of MacCast), and Jeff Gamet (Managing Editor at The Mac Observer). Listen to pro-tips and reviews of all your mobile Apples.
  7. MacCast is one of the longest running and most respected Mac podcasts. Host Adam Christianson keeps it fresh each show with Apple news, tips, and reviews.
  8. Mac Geek Gab, over at The Mac Observer, has the answers to your Mac questions. Hosts Dave Hamilton and John F. Braun answer listener questions, and offer new and useful nuggets each week.
  9. Mac Power Users just moved to, and is hosted by Katie Floyd, attorney, and David Sparks, also an attorney. But it’s not about law, just Mac geekery. If you want a podcast to explain how to get stuff done, this is for you. Warning: after they’re done explaining the best way to use the app of the day in your workflow, you will want to buy it.
  10. Puromac, our only Spanish language podcast, is over at the 5by5 network. Hosts Federico Hatoum and Flavio Guinsburg talk Apple-tini with a twist… one’s a former Windows guy.
  11. Rocket, over at, is our only all ladies hosted podcast. Hosts Christina Warren, Brianna Wu and Simone de Rochefort talk comics, games, tech… you know, geek fun.
  12. Systematic moved to not too long ago, and is hosted by digital tinkerer Brett Terpstra. (He’s also a huge TextExpander fan and has the snippet collection to prove it.) Listen to him interview interesting people armed with their top three picks of… something that interests them.
  13. Upgrade, over at, covers tech, all tech, and Apple tech, with the occasional detour. Jason Snell, former editor of Macworld magazine, continues to share his wealth of knowledge and insight into the Apple universe along with co-host Myke Hurley.

If you’ve heard an amazing podcast and want to share, we’re all ears.

Smile Goes to Yosemite (The Conference)

Posted 05/01/2015 by Maia

(Or, Way Too Many Smileworthy Things In One Blog Post)

Vernal Falls

Last week Smile was proud to sponsor Yosemite by CocoaConf. Not just an excuse for us to make our own Yosemite desktop art, this intimate get-together featured speakers from the world of development and design, relating valuable learned life experiences. (Need help dealing with burnout? How about tips on programming from the world of race car driving?) We’d like to thank all the speakers for sharing their carefully curated bits of wisdom.

When these talks come out as videos later this year, we encourage you to take a look and get inspired.

Posing for a #SmileMugShot below, Jason Snell of the Upgrade podcast and Serenity Caldwell of The iMore Show hiked and photographed Yosemite park with us. Smile sponsors both of their podcasts, where you can hear professional Apple enthusiasts talk about their favorite tech.

Mug ShotMug Shot

A few @AppCamp4Girls volunteers also made an appearance: Liz Marley, bug testing guru at the OmniGroup; Christa Mrgan of Rogue Amoeba, who spoke about good design and the High Sierra camps of Yosemite where she worked for a few summers; and our very own Maia Olson of Smile, posing for her #SmileMugShot below. App Camp For Girls is a Friend of Smile, and recently released their first ever app. If you’re a fan of getting girls inspired to code, buy their $.99 app for a good cause and see what 12-year-old girls do in app camp.

Mug Shot

Thank you Apple for naming the OS that inspired a beautiful conference. Thank you CocoaConf for running with that inspiration.

2 Day Deal: PDFpen for iPad & iPhone 40% Off

Posted 04/15/2015 by Maia

40% off

PDFpen for iPad & iPhone

2 Day Deal
40% off Thursday & Friday
Only on the App Store


Buy PDFpen 2, your PDF editor for iPad and iPhone, on the App Store for $11.99, Thursday April 16th and Friday April 17th.

With PDFpen 2, edit your PDFs anywhere you are! Sign contracts, scribble notes and highlights, make changes, fill out applications, and more on your iPhone or iPad. The only PDF editor available for both iPad and Mac, with iCloud and Dropbox storage & sync for seamless editing. Watch in it action!