Skip to Content

Free TUAW iPhone app -- try it now!
AOL Tech

Filed under: Features, How-tos, AppleScript

AppleScript: Integrating shell scripts


We've talked about AppleScript how-tos before. AppleScript is fun and all, but what if you already know how to write shell scripts? Well, did you know that by integrating shells scripts into AppleScript, you can create simple applications that do useful things? It's true, and I am going to show you how.

Continue reading to learn how to integrate shell scripts into AppleScripts.


What's a shell script?
A shell script is a way to automate a task by using a command line (i.e. using Terminal to access the underlying UNIX system in Max OS X). A simple "program" can be written that uses command line access to do a specific task.

How do I "Integrate shell scripts"?
Integrating your shell script into AppleScript is extremely easy. To do this, just use the "do shell script" command for AppleScript. So, your shell script will look similar to this:

do shell script "your script here"

What can I do with this shell script?
If you've never written a shell script in your life, don't worry. I have included some sample shell scripts below that can be used to forcequit applications and eject a disc from your Mac. Just copy these AppleScript into ScriptEditor.app (/Applications/AppleScript/ScriptEditor.app) and click the "Run" button to see the magic happen.

Kill an application

do shell script "killall 'application-name-here'"

Eject a disc from the Mac's drive

do shell script "drutil eject"


Saving shell scripts as Mac applications
You can save your completed AppleScript/shell script combos as applications (.apps) if you wish. To do this, simply type in your script and click File > Save as in the Script Editor's File menu. You can read this post for more information about saving AppleScripts as applications.


Important Update: Since last week, everyone seems to be a bit on the edge about running scripts (especially shell scripts). TUAW would like to remind everyone that you should only run AppleScripts/shell scripts from trusted sources.

Related Articles From The Unofficial Apple Weblog

Reader Comments (Page 1 of 1)

Tip of the Day

Use Spotlight as a reference tool. Type any word in the Spotlight box and one of the top entries will be a definition. Click on it, and it will bring up the dictionary application to check the word in either the dictionary, thesaurus, Apple database, or Wikipedia.


Follow us on Twitter!
 TUAW [Cafepress]

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Google Earth for iPhone
Podcaster
Storyist 2.0
AT&T Navigator Road Test
Bento for iPhone 1.0
Scrabble for iPhone
Tom Bihn Checkpoint Flyer Briefcase
Apple Vanity Plates
Apple booth Macworld 07
WorldVoice Radio
Quickoffice for iPhone 1.1.1
Daylite 3.9 Review
DiscPainter
Mariner Calc for iPhone
2009CupertinoBus
Crash Bandicoot Nitro Kart 3D
MLB.com At Bat 2009
Macworld Expo 2007 show floor

 

More Apple Analysis

AOL Radio TUAW on Stitcher