This is probably simple to do but I’m stuck. What I want to do is get the Finder to check if an application is open, if it is tell it to quit.
I can sort of get this to work, but each time I run the script, if the application I want to quit is closed it opens it to close it. The script basically does what I want but I just want to tidy it up. Any ideas
Thanks!!
I like that tell processes command! How can I get that command to help me pause a script until a certain application has quit for sure? In other words, I’m writing a script to tell an application to quit, then backup that application’s data file but I don’t want to run the backup step until the application has quit for sure.
You can create a “stay-open” applet, adding an “idle” handler, which will be executed every x seconds:
on run
--> do whatever
end run
on idle
tell app "Finder" to name of processes
if "App_to_check_for" is not in contents of result then --> "App_to_check_for" is not running
--> backup data
end if
return 5 --> this code will execute every 5 seconds
end idle
Thanks for the code. That sounds like what I want to do but I’m not sure where exactly that idle code tells the script to proceed if, and only if, the said app has quit. It seems to be proceeding to the backup step too soon still. Here is what I have so far:
tell application “4D Server”
quit with delay 1
end tell
on idle
tell application “Finder” to name of processes
if “4D Server_6.7.3” is not in contents of result then -->“4D Server_6.7.3” is not running
end if
return 2
end idle
tell application “Finder”
activate
select file “NFN_Ben_TN.data” of folder “NFN_Ben_STL” of startup disk
duplicate selection to folder “backup test” of startup disk replacing yes
end tell
In a stay-open applet with an idle handler, the first time is executed the “on run” handler. In the code you’ve posted, everything, except for the idle handler.
So, in a logical process, you should place your backup code within the if-end if statement, in the idle handler…
on run -- here you declare explicitly the run handler.
tell application "4D Server"
quit with delay 1
end tell
end run
on idle --> execute this every 2 seconds
tell application "Finder" to name of processes
if "4D Server_6.7.3" is not in contents of result then -->"4D Server_6.7.3" is not running; go ahead with the backup.
tell application "Finder" to ¬
duplicate file "NFN_Ben_TN.data" of folder "NFN_Ben_STL" of ¬
startup disk to folder "backup test" of startup disk replacing yes
end if
return 2
end idle