Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Run Terminal commands via AppleScript and shortcuts UNIX
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).
    •    
  • Currently 3.20 / 5
  You rated: 4 / 5 (5 votes cast)
 
[30,633 views]  

Run Terminal commands via AppleScript and shortcuts | 5 comments | Create New Account
Click here to return to the 'Run Terminal commands via AppleScript and shortcuts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Run Terminal commands via AppleScript and shortcuts
Authored by: jmd2121 on Dec 06, '04 04:54:16PM

thank you! been lookingfor this.

Are there any applescript experts out there that might know a way of capturing the output -- displaying it in an output screen?

Started using butler -- what a great ap! definately worth a donation.



[ Reply to This | # ]
Run the uncompiled script
Authored by: sinjin on Dec 06, '04 05:08:47PM
With your script you can quickly run a shell process without a terminal window associated with it. Pretty neat.

Is there a reason for making the applescript an application bundle (and then having to modify its contents to be background)? I tried this with saving the applescript as a script (not app) and it works fine. Doesn't have a start up delay and requires no special modification to hide.

Do the extra steps you detail serve a purpose associated with your launcher?

In case anyone is interested, you can get the result to display if you ask for it by adding:


set the_output to the result
display dialog the_output default button {"OK"}
Cheers

[ Reply to This | # ]
Run the uncompiled script
Authored by: ob1cannoli on Dec 07, '04 09:01:09PM

I made it an application because I also keep an icon of it on my desktop and in a folder in my dock. if you use a regular applescript on the desktop it will open in script editor...

your way works fine, but doesn't stop script editor from opening if you click the icon



[ Reply to This | # ]
Run Terminal commands via AppleScript and shortcuts
Authored by: boredzo on Dec 08, '04 03:34:05AM
... add the following:
<key>LSUIElement</key>
  <string>1</string>

the correct way to do that is with the true and false elements:

<key>LSUIElement</key>
  <true />



[ Reply to This | # ]
Run Terminal commands via AppleScript and shortcuts
Authored by: Peter Maurer on Dec 09, '04 03:37:23AM

Both seem to be correct. For instance, Panther's System Events.app uses <string>1</string>, while BOMArchiveHelper uses <true/>. I'm not sure if <true/> works with Jaguar or lower, though. At least, I've never seen it there.

---

http://www.petermaurer.de/butler/



[ Reply to This | # ]