PDA

View Full Version : applescript leaves terminal window open




Zeke D
Jul 22, 2012, 09:46 AM
I am using the following script:



tell application "Terminal"
activate
do script "cd /Volumes/iTunes/" in front window
do script "./ToastImageMounter ZooTycoon2NoCD.toast" in front window
do script "open 'Zoo Tycoon 2.app'" in front window
do script "exit" in front window
close front window without saving
end tell


It prompts me to click on the close button in the terminal window, and still leaves terminal active in the dock. what modifications would you suggest? If I could I wouldn't even have a terminal window at all.



Red Menace
Jul 22, 2012, 12:41 PM
You can use do shell script from Standard Additions - see Technical Note TN2065 (http://developer.apple.com/library/mac/#technotes/tn2065/_index.html). Note that each do shell script statement runs in a separate generic shell, but a semicolon can be used to separate multiple commands in a single statement. Using && to separate commands will stop later commands if there is an error, for example:

do shell script "cd /Volumes/iTunes/ && ./ToastImageMounter ZooTycoon2NoCD.toast && open 'Zoo Tycoon 2.app'"

Zeke D
Jul 22, 2012, 01:27 PM
Thanks that helped.

I used the same methodology to do the following:


do shell script "hdiutil attach '/Volumes/iTunes/SimCity 4 Rush Hour.dmg' && open '/Volumes/iTunes/SimCity 4 Deluxe/SimCity 4 Rush Hour.app' && hdiutil detach '/Volumes/SimCity 4 Rush Hour'"


of course detach detaches right away, and SC4 barfs. can applescript do loops?

chown33
Jul 22, 2012, 02:04 PM
What purpose would a loop serve?

This is a request to explain what you're trying to accomplish (the intended purpose of a loop), rather than how you're trying to accomplish it (with a loop).

I think you might be asking how a delay can be inserted, but I'm not sure about that, since neither a delay nor a loop would let you detach the DMG while an app is still running from it. If the intent is to wait until the app has quit before detaching the DMG, then that's a bigger problem to solve than "Can AppleScript do loops?".

Zeke D
Jul 22, 2012, 02:09 PM
What purpose would a loop serve?

This is a request to explain what you're trying to accomplish (the intended purpose of a loop), rather than how you're trying to accomplish it (with a loop).

I think you might be asking how a delay can be inserted, but I'm not sure about that, since neither a delay nor a loop would let you detach the DMG while an app is still running from it. If the intent is to wait until the app has quit before detaching the DMG, then that's a bigger problem to solve than "Can AppleScript do loops?".

Indeed. I would want it to detach the dmg after the program has finished running.

Red Menace
Jul 22, 2012, 02:36 PM
You will need some way to determine when the application quits - your script can poll the running applications via System Events, or if your script is a Cocoa-AppleScript application it can register as an observer via NSWorkspace, or you can install something like Do Something When (http://www.azarhi.com/Projects/DSW/), etc.

Zeke D
Jul 22, 2012, 02:44 PM
You will need some way to determine when the application quits - your script can poll the running applications via System Events, or if your script is a Cocoa-AppleScript application it can register as an observer via NSWorkspace, or you can install something like Do Something When (http://www.azarhi.com/Projects/DSW/), etc.

Sounds like polling or system events would add extra CPU/memory cycles. I guess leaving the images mounted is not a big deal, as they cold o ly be used to load he programs again. Thanks for the help guys.