Automator service script ALWAYS launches application, disregarding conditional
El-Capitans security restrictions are NOT responsible for erroneous behaviour above. I tested the script some more and found that:


Any "is running"-phrase needs to have a short "delay" in front of it to  reliably return a true answer ... but still won't do so if called as an app's service.
Furthermore I guess that Automator scripts are somehow "pre-processed" before being run as Services.
All if-branches are evaluated (played through) and thereby activated "just in case".


In jweaks code at stackoverflow, iTerm is only affected directly in the 2nd clause ("tell ...").

tell application "System Events" to set theProcesses to name of every ¬
    every process whose visible is true

if theProcesses contains "iTerm" then display notification "running"
else [...]



Try this code in ScriptEditor, Automator and as Service in Safari:

display notification "" &amp; running of application "TextEdit"
tell application "TextEdit" to activate
quit application "TextEdit"
display notification "" &amp; running of application "TextEdit"


You will get different results from AppleScript/Automator (=> false + true) and Safari (true + true).
Especially AppleScript/Automator's true from the 2nd notification is quite telling.

... however, if you insert just a minute delay, say 0.01, after the "quit" line, running will be tested as "false" - if the script is run from within AppleScript/Automator.