Writing a script to close itself automatically after launching an app

I want to write an Apple Script to launch Firefox with a specific profile. After firefox is launched, the script should automatically close.

The current script is like this.
do shell script "exec /Applications/Firefox.app/Contents/MacOS/firefox-bin -p Junk"
tell me to quit

But the apple script app doesn't quit after launching firefox. It seems like "Do shell script" is a blocking call. Is it possible to "call" firefox and return immediately?

I tried suffixing &. But still no luck... 😟

MacBook 2.4 GHz Aluminium, Mac OS X (10.5.6), iPhone OS

Posted on Sep 28, 2009 6:30 AM

Reply
4 replies

Sep 28, 2009 7:42 AM in response to MugunthKumar

You shouldn't need to do anything special - the script should automatically quit once it's done its thing. You don't even need the 'tell me to quit' line.

There are only three cases where a script should stay open indefinitely.
The first is if you have a repeat loop or command that doesn't exit.
Second is a script with an 'on idle()' handler
and the third is an app saved with the 'Stay Open' option checked in the Save dialog.

If what you've posted is your entire script it could be the latter. Re-save your script and ensure the 'stay open' option is not checked.

Of course, that being a 'rule', there are always exceptions. In this case since you're using 'do shell script', AppleScript may be waiting for the shell command to exit before it thinks the AppleScript is done.

For 'do shell script's to return control to the AppleScript, you need a little more than the '&' on the end.
You also need to redirect stderr and stdout, which you do by appending:

>/dev/null 2>&1


to the command. This redirects the output of the command, returning control to the AppleScript.

Sep 28, 2009 9:19 AM in response to MugunthKumar

Try this...

<pre style="margin:0px;padding:5px;border:2px dotted green;width:630px; height:auto;color:#ffffff;background-color:#000000;overflow-x:auto;overflow-y:h idden;font-family:Verdana, Monaco, monospace;font-weight:bold;font-size:12px;"
title="Copy this text and paste it into your Script Editor application.">do shell script "exec /Applications/Firefox.app/Contents/MacOS/firefox-bin -p Junk &> /dev/null &"</pre>

Hope this helps...

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.

Writing a script to close itself automatically after launching an app

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