Use TextExpander to Launch Applications and More

by Bakari Chavanu Jun 06, 2008

Like many other Mac users, I use QuickSilver, Spotlight, and sometimes the little buggy, mouse-drive controlled launcher, Sapiens, to launch applications, websites, folders, and documents. But the other day, I realized that I could use the AppleScript feature of the text expansion plug-in, TextExpander to launch applications and perform other functions without having to rely on the often required command, option, or control keys to for keyboard shortcuts.

Using the TextExpander method I'm about to show you, you can create AppleScript commands to launch applications, close Finder windows, create new TextEdit documents, and much, much more depending on your AppleScript skills. With this method, you save a step or two of having to call up Quicksilver or Spotlight to type in a command. Just as you use TextExpander abbreviations to spell out words and phrases, you can use TextExpander's Applescript command feature to run scripts using assigned abbreviations. So instead of using Command-Q to quit a selected application, you can quit say Yahoo Messenger even if it's in the background with a simple AppleScript and abbreviation like say "qy" (my abbreviation for quitting Yahoo Messenger.) Since using this method, I now open up frequently used applications, create new TextEdit document, and rate a currently playing iTunes song on the fly.

Note, however, that this TextExpander method doesn't seem to always work when you have the TextExpander/System Preferences as the front most window on your desktop. Also, if you use these abbreviations while typing in a document, the first letter of the abbreviation will appear before the script is executed. So if that's a problem, you may not want to use this method. Or in this case, you can simply switch to the Finder and then type your needed abbreviation.

So here's how to create a script and use it in TextExpander: 

1. Open up that old crusty Script Editor (it's in your application's folder) that you may not have ever used in a while. If you're not a developer, Script Editor might seem like a foreign language, but for our needs, it's pretty much a copy and paste procedure. 

In Script Editor click File>New, and copy and paste the following sample script in the editor: 

tell application "Finder"

activate application "iCal"

end tell

Click the Run button to make sure it works for you. There's no reason it shouldn't.

2. Now open up TextExpander and create a new snippet as you normally do. Paste your script in the contents column on the right. Choose Content: AppleScript from the drop down list at the top of the TextExpander window. If you don't choose this feature, the command of course won't work.

Now create an abbreviation for activating your script. I chose "ical" (without the quotation marks of course) and kept it case sensitive so that I could still type "iCal" with a capital C, which means the script will only run when I use the lowercase c.

Now from within any application or the Finder, you should be able to type "ical" and the connected script in TextExpander  will open iCal for you. If you're writing in a document, the "ical" abbreviation will partially appear, but the script will run anyway. Remember, you can always just switch to the Finder and then type the abbreviation if you don't want to be bothered by this little issue. 

That's it for this example. To create another similar script like this, you can replace "iCal" in this script with the exact name of another application. Also, you really don't need to save the scripts you create in AppleScript because they're now saved in TextExpander.

If you find yourself creating more scripts for this method, you will probably want to create a separate folder in TextExpander to house your script commands. 

Here are some more short and sweet ideas for scripts. It's a good idea to test these scripts in the Script Editor before applying them in TextExpander.

tell application "Finder"

quit application "iChat"

end tell

Replacing the word "activate" with the word "quit" in the first script above is a quick way to close an application. I know you can use Command+Q to quit an application, but with the TextExpander method, you can quit a specified application without it being activated. I use "qc" for this one. 

tell application "Finder"

activate

end tell

This one switches you to the Finder without having to use your mouse or the tab key.  

I don't personally use this one, but I thought it might be handy and simple enough for others.  I might assign "ff" to this one if I used it. 

tell application "Finder"

if the (count of windows) is not 0 then

close every Finder window

end if

end tell

This script closes every opened Finder window. I use the abbreviation, "qq" for this one. It's a quick way to close out windows on my desktop from with any application.

If you just want to close one window at a time, a short abbreviation like "ff" is faster than Command-W in my view. And again, you can as far as I can tell do it from within any application. Here's the short script for closing the top most Finder window.

tell application "Finder"

activate

close Finder window 1

end tell

Here are a few more script ideas.

tell application "iTunes"

play track "Feelin' Good" of playlist "Library"

end tell

This one plays my favorite song to date. (When you copy and paste the script, simply replace my song title with the exact name of your favorite song title.) The TextExpander abbreviation I use for running this script is "fs" simply because it best describes the function and it's key combination I'd rarely if ever type otherwise. Or you might just use "favoritesong" so you can remember it even better. Just make sure the two words are joined together. Also what's neat about this, is when "Feelin' Good" ceases to be my favorite song, I can quickly change it to another one in TextExpander. 

tell application "iTunes"

set rating of current track to 100

end tell

I use QuickSilver to rate my iTunes songs on the fly, but with this script, I can rate a current playing song 5 stars just by clicking my assigned abbrevation, "rr" instead of the Command-r that I used with Quicksilver. A little faster in my view. By the way, I learned that ratings in iTunes are rally like 0-100. 100 being 5. For my purposes, I rate all my iTunes songs a 3 when they're first imported, and I re-rate favorite selected songs a 5. I don't bother with numbers in between.

tell application "TextEdit"

activate

make new document at the front

end tell

This one creates a new TextEdit document. My abbreviation: "tte." This script saves me like three steps in the usual process for creating a new document.

tell application "TextEdit"

activate

save every document

end tell

Saves every open TextEdit document I have open. I like this one better than Command+S because I can type the abbreviation "sd" ("save documents") faster in my hand than the Command+ option. Of course, this doesn't work well when you're actually typing in a TextEdit article because the first letter of the abbreviation will appear and that you have to save the document again. So it's best to simply switch to the Finder and then type the abbreviation for this script when you want to save one or more documents at the same time.

tell application "Safari"

activate

open location "http://news.google.com/"

end tell

I use "hh" to call up my Safari homepage. I call up this page throughout the day to check news, and this short key is surely a time saver. Of course, just substitute the URL in the example above with your own. 

There's really no limits to the scripts you can create, but I'm in no shape or form a skilled script developer. I use Adam Goldstein's AppleScript: The Missing Manual (O'Reilly Press) and Stephen G. Kochan's Beginning AppleScript (Wiley Publishers) to help me with my script writing needs. AppleScript also comes installed with a set of default scripts that you might find useful.

Finally, I want to add that you can actually make a print out of your TextExpander abbreviations and commends so to help you remember them, or can you write abbreviations on a yellow sticky and affix it to your monitor for quick preview. Just use the print feature TextExpander to accomplish this.

If you come up with additional short scripts that others might want to use with TextExpander, feel free to post them in your comments.

Comments

  • With a short TextExpander abbreviation, you can open or quit a program, navigate to a website, close all Finder windows, and more. -Tire Works

    Tire Works had this to say on Aug 10, 2011 Posts: 12
  • Page 1 of 1 pages
You need log in, or register, in order to comment
MySQL ERROR:

Error Number: 1064

Description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Query: SELECT country FROM exp_ip2nation WHERE ip_range_low <= '64'' AND ip_range_high >= '64'' ORDER BY ip_range_low DESC LIMIT 0,1