Skip to Content

Massively looks at the best free to play games
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.

Reader Comments (Page 1 of 1)

Tip of the Day

To find out what version of Mac OS you are running, go to the Apple logo in the top left corner, click it and choose About This Mac. From that window you will see the version number, processor, memory and chosen startup disk. Clicking Software Update will check for updates, and More Info... will open up an extensive list of everything on your machine.


Follow us on Twitter!
TUAW [Cafepress]

Sponsored Links

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Google Earth for iPhone
Podcaster
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
Apple Texas Hold 'Em

 

More Apple Analysis

AOL Radio TUAW on Stitcher