This is a strange one: If the app FootTrack is not open the script works fine. If the app is open the script returns an error “Connection is invalid” and highlights the last “activate” in the script
tell application "System Events"
if (name of every application process) contains "FootTrack" then
display dialog "FootTrack needs to quit to switch libraries" buttons {"Cancel", "OK"} default button 2
tell application "FootTrack"
quit
end tell
else
-- FootTrack is not running
end if
end tell
try
set new_path to "/Users/tim/Movies/FootTrack/Family"
set this_data to do shell script "defaults write com.foottrack.FootTrack CatalogLocation " & " " & new_path
on error
display dialog "Could not change libraries." buttons {"OK"} default button 1
end try
tell application "FootTrack"
activate
end tell
Am I stuck in a loop I can’t see? Any ideas are most appreciated!
:shock: I don’t know what that has to do with the original script and I don’t have any more suggestions to ignore. Hopefully someone else can help you with your problem.
My guess is that you’re not giving enough time for the app to quit before trying to re-activate it.
In one statement you tell the app to quit. The process of doing this establishes a connection between AppleScript and the app.
You then shuffle the files around and rewrite the preferences before the app has finished quitting. When you try and re-activate the app, AppleScript is still trying to target the quitting app.
Try adding a delay to your quit routine - either a simple delay x statement or, better still, a check for its actual status, like:
...
tell application "FootTrack"
quit
end tell
repeat until (name of every process) does not contain "FootTrack"
delay 1
end repeat
In this case the code will loop until the app really has quit, then you’re safe to continue.