Filed under: Features, How-tos, Productivity
AppleScript: build a simple task launcher
If you're like me, when you sit down at your Mac, you end up opening a few specific apps depending on what kind of project you're working on. I am going to show you how you can group these applications into "task launchers" that will bring up a suite of programs with one click. For instance, I have a script that will open iPhoto, iDVD, and iMovie called "Create Movies." When I run this script, it will open all of the applications I need to make my movie. I also have one called "Productivity" that will, when opened, launch Mail, iChat, Pages, and Yojimbo (even though some might argue with iChat's productivity value). Want to make your own launchers? Continue reading for the instructions.
Writing the Script
To create this script, you will use the tell command -- you may recall that this tells a specific application to do a specific task. Open the Script Editor and type the following script:
tell application "X" to activate
Replace the "X" with your application of choice. For example, if you wanted to add Mac OS X's Mail application, you would type:
tell application "Mail" to activate
Remember to include the quote marks around the application name (this helps to prevent errors for some applications). You can repeat this tell command for as many applications as you would like to open. When you're done, your AppleScript should look something like this:

Once you have your script typed, let's save it. We'll save this application as an application bundle (as noted in the post on how to save AppleScripts, application bundles will allow you to save a universal application; in other words, it will work on both Intel and PowerPC Macs).
Go to the save dialog (File > Save). Once there, let's tweak some save settings. In the "File Format" drop-down menu, select "Application bundle." You can also check the "Run Only" checkbox (if you don't want people to see your script after it is saved).

You can repeat the steps above to create as many of these task launchers as you would like. To activate the script, just double click on its icon. If you want to streamline a bit further, you can place these scripts in the dock, either among the applications or in a folder so you can make a stack out of them.
To create a stack, just make a new folder in a convenient location (perhaps a "Launchers" folder in your home directory), drag-and-drop the scripts that you've created into your new folder; then drag the entire folder to the right side of the divider in the dock. You now can have multiple applications launch with just two clicks!

There you have it, your very own "no-duct-tape-required" task launchers!
Get a WordPress.com Blog
![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 2)
Ratkat said 2:10PM on 2-02-2008
This is a great tip, is it possible to change the icon of the saved script?
Reply
Frank said 11:14PM on 2-10-2008
It probably would have been a good idea to note that if you replace activate with run, the app starts running, but no window will open.
for instance:
tell application "NetNewsWire" to run
will open the application, it will appear as running in your dock, but the app itself will be hidden, eliminating the need to minimize it.
In scripts I have that serve this same purpose, I have a mixture of apps that I "run" and others that I "activate" or else my desktop would become cluttered!
Halopend said 2:32PM on 2-02-2008
Yes, you can change the icon, like anything in osx by following the method here
http://paulstamatiou.com/2005/12/07/how-to-quickie-change-os-x-icons
Reply
Adam said 4:13PM on 2-02-2008
Awesome tip!
Is there a way to minimize a specific application upon activation?
Reply
Ken Carpenter said 6:32PM on 2-02-2008
Loved the tip!
But I'm still an AppleScrpit idiot . . .
Here's a simple task I'd like to automate, maybe you can write a script for it?
-- Open Safari
-- Choose History>Clear history
-- Choose Safari>Empty cache>OK
-- Choose Safari>Private Browsing>OK
Might make another great tip!
Reply
Brian Christmas said 10:15PM on 2-02-2008
G'day Ken
Try this, saved as App...
tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
click menu item "Clear History" of menu 1 of menu bar item "History" of menu bar 1
click menu item "Empty Cache…" of menu 1 of menu bar item "Safari" of menu bar 1
delay 0.5
click button 2 of window 1
try
click menu item "Private Browsing…" of menu 1 of menu bar item "Safari" of menu bar 1
delay 0.5
click button 2 of window 1
end try
end tell
end tell
end tell
Regards
Santa
Alex said 5:31PM on 2-02-2008
Wow. I was just thinking about how I needed to write something like this this morning.
Reply
Brian Christmas said 5:49PM on 2-02-2008
G'day from Oz
I wrote a script last year that allows you to create and build multiple lists of not only Apps, but folders to be opened.
http://scriptbuilders.net/files/launcher1.1.html
If you don't want to do your own scripting, then try it out.
Santa
Reply
Sean said 9:33AM on 2-03-2008
Thanks for the tip on my NAS problem. I now have a one-click solution for mounting drive and launching iTunes.
Sean said 6:06PM on 2-02-2008
I have my iTunes library on a networked hard drive. Is there a way to build a script that would connect to the hard drive and then launch iTunes?
Reply
Brian Christmas said 7:46PM on 2-02-2008
G'day Sean
Automatically mounting a networked drive is a little bit involved, especially if it's password protected. You'll need to write a script for your specific circumstances.
Try this search on MacScripters to see solutions.
http://tinyurl.com/38w69h
Once mounted, use a script to open iTunes, and if the Library preferences are set to the networked drive, all should be well.
Regards
Santa
Brian Christmas said 6:26PM on 2-02-2008
Oops, that should have read files, not folders.
Anyway, if you want to use my script (which is actually an Application), just copy it and rename the copy to a suitable name. Run it, and you're asked to build a list of Apps/files belonging to that particular named copy.
The list of Apps/files is stored in a hidden file at desktop level, (the file names are the same as what you name the copy, but starting with a period). The list can be altered anytime you open the script.
If you ever want to Trash the hidden file, then use something like File Buddy, (or write a script to remove the period at the start of the name, which will make it visible).
Regards
Santa
Reply
Ken Carpenter said 11:18PM on 2-02-2008
Santa,
I can't seem to get it to run . . .
In what format do I save the script?
Ken
Reply
Brian Christmas said 11:49PM on 2-02-2008
Ken, you need GUI scripting turned on.
Run this
-- The GUIScriptingAvailable handler is intended for use in any script that needs to determine whether GUI Scripting is available. It is omitted from the other GUI Scripting scripts in this collection in the interests of simplicity.
-- Written by Bill Cheeseman, PreFab Software, Inc., April 2005.
get GUIScriptingAvailable(true) -- test the handler with interaction
tell current application to display dialog "GUI Scripting is available: " & result buttons {"OK"} default button "OK"
on GUIScriptingAvailable(withInteraction)
-- Return true if running Mac OS X 10.3.0 or newer and access for assistive devices is enabled, else return false. If withInteraction is true, report negative result to user and, if Mac OS X 10.3.0 or newer is running, launch System Preferences, wait for user to set access and dismiss System Preferences, then return new setting.
get system attribute "sysv"
if result is greater than or equal to 4144 then -- 4144 is Mac OS X 10.3.0
tell application "System Events" to get UI elements enabled
if result then -- GUI Scripting is available
return true -- exit immediately
else -- GUI Scripting is not enabled
if withInteraction then
try
tell current application to display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check \"Enable Access for Assistive Devices\" in the Universal Access preference pane." with icon stop
on error number -128 -- user canceled
return false
end try
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
end tell
tell application "System Events"
repeat -- stall script until user decides
if exists process "System Preferences" then
delay 1 -- yield CPU time to other processes
else -- user closed System Preferences
return UI elements enabled
end if
end repeat
end tell
end if
return false
end if
else -- Mac OS X 10.3 Panther or newer is not running
if withInteraction then
tell current application to display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit"
end if
return false
end if
end GUIScriptingAvailable
Joe said 9:00AM on 2-03-2008
Back in the day (on the Mac) when entire programs were smaller (in bytes) than the size of the icons for apps are today I wrote a little utility that did exactly this. It's so funny to see all these types of ideas from years past resurfacing in new ways. Back in the day I called them "Launch Boxes" - a play on words since they were like a "lunch box" - a collection of apps or documents - that would launch. It's alot easier these days for the average user to implement these types of useful utilities though! Good work!
Reply
enas said 9:35AM on 2-03-2008
On the same kind of considerations, I just wanted to mention the excellent open-source programme Marco Polo, which is basically a location manager, but which associates with a location the notion of a task (at work, launch these apps and at home those other ones). But it can be used as a simple task switcher, even if the actual location doesn't change. At least, that's my opinion.
Reply
Jerry said 9:54AM on 2-03-2008
Can you make it so it opens Safari in a specific URL and Address Book in a specific contact?
Blue skies!!
Reply
DanRobinson said 10:53AM on 2-03-2008
Here's my "Good Morning" script:
tell application "Finder"
activate
set TheLocation to folder "Good Morning" of folder "Favorites" of folder "Library" of folder "daniel" of folder "Users" of startup disk
open {internet location file "MacMinute.webloc" of TheLocation, ¬
application file "Mail.app" of folder "Applications" of startup disk, ¬
application file "NetNewsWire.app" of folder "Applications" of startup disk, ¬
internet location file "The Unofficial Apple Weblog (TUAW).webloc" of TheLocation, ¬
document file "z Astronomy.url" of TheLocation}
end tell
Reply
Karl said 6:10PM on 2-03-2008
I love applescripts so much, and it's stunning when people don't know of or use them. Thanks!
Reply
rhix said 1:51AM on 2-05-2008
If you're looking for a GUI for doing these types of things, you could check out our product, NetworkLocation, which will allow you to start applications, mount network drives, run custom scripts, and set a ton of system settings. Pretty much every request I've seen in the comments here can be handled in NetworkLocation via our easy to use GUI.
Reply