Apple script hang up

When i run an applescript it does it's job (runs a shell script) but then hangs up and i have to force quit it. Is there a shell script or apple script i could run to tell it to force quit without knowing the number of the running process? This is as i would like to not have to find out the process id number each time i run the script as it changes each time...
thanks - 7;^')

MBP 2.16 Core Duo, Mac OS X (10.4.11)

Posted on Dec 19, 2007 5:12 AM

Reply
6 replies

Dec 19, 2007 10:21 AM in response to LittleAnt

Is the shell script a long-running process? If so, it may just be that AppleScript is waiting for the shell script to finish before it finishes itself.

There are ways of overcoming that - namely telling the shell to run in the background and not to have AppleScript wait for it to finish.

Alternatively there are ways of capturing the PID of the shell command which you can use to later kill the process, but the fact you think you need to kill the process implies that AppleScript isn't the problem itself.

Dec 19, 2007 2:42 PM in response to LittleAnt

Sorry, was in a hurry when i wrote that.

do shell script "/System/library/Frameworks/Screensaver.framework/Resources/ScreenSaverEngine.a pp/Contents/MacOS/ScreenSaverEngine -background &"

It's the one to make the Desktop display as the Screensaver. How would i capture the process? And if the program is called "Screensaver Background" how could i killall it?
Thanks 7;^')

Dec 19, 2007 2:57 PM in response to LittleAnt

There are two elements here.

First, AppleScript is, indeed, waiting for the process to finish before ending itself, so the first step would be to have AppleScript not wait for the process to end and return control immediately.

In order to do that you need to add some addition elements to the shell command, specifically " > /dev/null 2>&1' before the trailing &, like:

<pre class=command>do shell script "/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.a pp/Contents/MacOS/ScreenSaverEngine -background >/dev/null 2>&1 &"</pre>

These additional elements suppress the output of the command (which you don't care about anyway) and allows AppleScript to continue while the shell command continues to execute in the background.

For the kill element there is an additional part, echo $!, you can use that returns the PID of the command just executed. You can store this and use it later to kill the process.

This example launches the screensaver for one minute, then kills it.

set myPID to do shell script "/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.a pp/Contents/MacOS/ScreenSaverEngine -background &> /dev/null & echo $!"
delay 60
do shell script "kill " & myPID


You could also use killall, but since this kills processes by name, not PID, you run the risk of killing other processes at the same time.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Apple script hang up

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.