I am having issues with applescript, where whenever I open an applescript file (either in AppleScript Editor or in Automator) it will automatically open any programs mentioned in a tell statement/block. Most of these tell blocks are only reachable through conditionals and I would like to find a way to stop applescript’s default behavior of opening all mentioned applications.
This is basically what I am doing:
if currentApplication is "Application 1" then
tell application "Application 1"
do stuff
end tell
else if currentApplication is "Application 2" then
tell application "Application 2"
do stuff
end tell
end if
Unfortunately, whenever I open this script it will open both “Application 1” and “Application 2” if they are not open yet, even though it should only get to the tell statements if one of the applications is open. The way I get the current application is not really relevant, even if my ‘if’ statements were “if false” and I cut out the method that gets the “current” (or closest) application, the applications will still be opened along with the applescript.
If you just run a compiled script, an application will only be launched if AppleScript needs to send it a command, but if you open the script in a script editor, all of the applications referenced in the script will be launched in order to get their custom terminology – see the AppleScript Release Notes.