• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

Applescript to shell script

ChristTrekker

Well-known member
Any Applescripters out there? I want to wrap a shell script so that I can double-click an icon to run it. If possible, it would be great to have some feedback via dialog box too. How can I do this?

The shell script just identifies some processes and kills them. If this can be done completely via Applescript, that might be even easier, rather than trying to get the two to talk??

 

porter

Well-known member
I want to wrap a shell script so that I can double-click an icon to run it.
You could start by telling us what platform, OS version etc you want to run this on! :)

 

PowerPup

Well-known member
Any Applescripters out there? I want to wrap a shell script so that I can double-click an icon to run it. If possible, it would be great to have some feedback via dialog box too. How can I do this?
The shell script just identifies some processes and kills them. If this can be done completely via Applescript, that might be even easier, rather than trying to get the two to talk??

If I understand your questions.

You're trying to make it so when you double-click applescripts so that it runs the script instead of opening the editor? You need to save the applescipt as an application.

("Save as" in the Applescript editor, it will give you a drop-down menu with options)

As for telling identifying processes and killing them. In applescript you need to know the name of the application (or process) you want to quit. For example "Finder." (Remember, It's case sensitive!)

tell application "Finder"quit

end tell
(Can't remember if the quotation marks are needed. Oh well, you can try with or without. See what works.)

Have fun Apple Scripting! (Someone even made a addon so you could use JavaScript to control things on your Mac. :O )

P.S. I'll make another post about dialog boxes. Need to go see my old script to remember and stuff. :p

 

ChristTrekker

Well-known member
You could start by telling us what platform, OS version etc you want to run this on! :)
OS X 10.5.smthg, PPC. Sorry, I figured Applescript had been fairly well standardized for awhile in most ways that would matter here.

As for telling identifying processes and killing them. In applescript you need to know the name of the application (or process) you want to quit. For example "Finder." (Remember, It's case sensitive!)
Part of the problem is that I want to kill extra copies of a daemon process. I don't know why it's spawning children of itself, but there only needs to be one running. I don't want to kill them all, just all but the first. I can whip this out in a shell script fairly easily, but don't know how I'd do it in AS. The goal is that when I notice my load average starting to creep up, I can just hit my "daemon killer" and clean it up easily. If it could report extra details (# of procs, load at the time, etc) - again, the type I can get fairly easily in my shell script - that would be nifty.

 

PowerPup

Well-known member
Ah, I see.

It would probably be easier to just use shell scripting and save it save the results to a text file. Then you would open the text file manually.

But, you could try to use both apple script and shell script for a more GUI feel. :D

It would go probably something like this:

AS: check if file "results" exists, delete if so,

AS: run daemon killer shell script.

SS: Does it's job and saves results in a file called "results"

AS: After waiting 5 or so seconds, (How ever long it take the shell script to do it's work.) Tell application "terminal" to quit.

AS: read "results" file and display info using display dialog command. (How it would display the info would take some work...)

This may be somewhat difficult to do though... Especially in AppleScript. It may be handy to also use JavaScript OSA

JavaScript OSA is a port of the Mozilla JavaScript scripting system to the Macintosh in the form of an OSA (Open Scripting Architecture) component. This way you could use JS to handle the pop-up boxes and such. (Or you may not need JS at all.)

Quite a bit of work. But an interesting idea none the less. :D

 

bear

Well-known member
Is there any reason you can't just double-click the shell script? If the executable bits are set, it automatically becomes a "unix executable" in the Finder. Some extensions (.sh, .pl, maybe others) defeat this behavior and cause the file to open in TextEdit.app regardless of executable bits. But, your script doesn't need a filename extension to run. Remove it and be happy.

Double-click it, it will start Terminal.app, and execute in a terminal window. The window will stay open after the script ends, for you to review any output.

I assume we're talking about OS X here and not A/UX.

 

macgeek417

Well-known member
To display a dialog of the output of the shell script "/foo/bar.sh",

Code:
display dialog (do shell script "/foo/bar.sh") buttons "OK"
that should work

 

ChristTrekker

Well-known member
To display a dialog of the output of the shell script "/foo/bar.sh",

Code:
display dialog (do shell script "/foo/bar.sh") buttons "OK"
that should work
Wow, sweet! I am looking forward to trying this.

Maybe I finally have to get around to teaching myself some Applescript...

 
Top