This is something I use every day. I don’t want all my apps opening at launch and I like an uncluttered dock. I have several of these scripts for task-specific batch application launching.
Also has a console logging feature which is kind of handy too.
DJ Bazzy Wazzy suggested I increase the security of the do shell script call with tell current application to. So I did that too.
--
-- Created by: Lorin Rivers
-- Created on: 6/5/14, 6:17 PM
--
-- AppleScript App Launcher by Lorin Rivers is licensed under an
-- MIT License.
--
-- Pass the application name to the function appLauncher
-- This AppleScript will request your admin password because it writes
-- to the system log. Other than that, it should be completely harmless.
--
-- provide a list of applications you want to launch in this form:
-- set launchThis to my appLauncher("Google Chrome Canary")
--
set myName to ""
--tell application "System Events" to set myName to get name of (path to me)
set launchThis to my appLauncher("Google Chrome")
set launchThis to my appLauncher("Skype")
on appLauncher(appName)
-- call System Events to discover if an app is running or not
tell application "System Events"
set myName to get name of (path to me)
-- if there are no apps named appName running
if (count (every process whose name is appName)) = 0 then
-- write to the system log. If the admin password request
-- is a concern, comment out every "tell current application to do shell script" line
tell current application to do shell script "logger " & myName & ": " & appName & " is not running" with administrator privileges
-- ask Finder to launch the app named appName
tell application "Finder"
try
tell my application appName
ignoring application responses
activate
end ignoring
end tell
-- write to the system log
tell current application to do shell script "logger " & myName & ": " & "starting " & appName with administrator privileges
-- something bad happened
on error errMsg number errNum
tell current application to do shell script "logger " & myName & ": " & "The errors are: " & errMsg & ": " & errNum with administrator privileges
end try
end tell
-- app named appName is running
else
tell current application to do shell script "logger " & myName & ": " & appName & " is already running" with administrator privileges
end if
end tell
end appLauncher