Run Terminal commands via AppleScript and shortcuts

Dec 06, '04 09:09:00AM

Contributed by: ob1cannoli

Using an application like Butler, and a quick background-only AppleScript, you can run a shell command via a keyboard shortcut. I find it pretty useful for quiting stubborn apps. Note however, that it won't return the result of the command -- it only runs it.

First, create this AppleScript:

set thecommand to text returned of ¬
 (display dialog "Run Script:" default answer "")
do shell script thecommand
and save it as an Application Bundle, with Start-Up Screen off. Next, open the saved application bundle (Control-click on it and choose Show Package Contents) and go to Contents -> Info.plist. Right after these lines...
<key>LSPrefersCarbon</key>
	<true/>
... add the following:
<key>LSUIElement</key>
  <string>1</string>
This will make the script backgorund-only (yes, this will also work for any application bundle, as explained in this older hint). Finally, set up Butler (or another application that lets you define key commands), and tell it to run the app. When the app runs, enter your command, and it will be executed (remember, though, that you won't see its output).

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2004120314311760