I’ve been trying to clean up my scripts and here is one that I have a question with:
launchApp("iTunes")
launchApp("Mail")
launchApp("iCal")
launchApp("Safari")
on launchApp(appName)
do shell script "$(ps -Aco command | grep -i '^'" & quoted form of appName & "'$' || open -a " & quoted form of appName & ") &>/dev/null &"
end launchApp
I don’t know if I made the script or copied it from somewhere and maybe modified it.
But my question is why would I run this app from unix with a do shell script instead of just running it with AppleScript?
I’d prefer the AppleScript equivalent.
Normally “ if the application argument is not a literal string “ you have to add an using terms from block to resolve the specific terminology, but in this case all 4 apps know the terms running and launch
launchApp("iTunes")
launchApp("Mail")
launchApp("iCal")
launchApp("Safari")
on launchApp(appName)
if application appName is not running then launch application appName
end launchApp
I would change that last script a bit and use the application id, because it isn’t mutable - unlike the app-name.
launchApp("com.apple.iCal")
launchApp("com.apple.iTunes")
launchApp("com.apple.mail")
launchApp("com.apple.Safari")
on launchApp(appName)
if application id appName is not running then launch application id appName
end launchApp