on run argv
if script = class of argv then
set is_startup to true
else
set is_startup to (item 1 of argv)
end if
set apps to {}
set apps to apps & {{name:"iStat Menus", ac_power:true}}
set apps to apps & {{name:"Moom", ac_power:true}}
set apps to apps & {{name:"ClipMenu", ac_power:true}}
set apps to apps & {{name:"Bartender 2", ac_power:true}}
set apps to apps & {{name:"HyperDock Helper", ac_power:true}}
set apps to apps & {{name:"Amphetamine", ac_power:true}}
set apps to apps & {{name:"Flux", ac_power:true}}
set apps to apps & {{name:"HazeOver", ac_power:true}}
set apps to apps & {{name:"ShadowsocksX", online:true}}
set apps to apps & {{name:"Firefox", ac_power:true, online:true}}
set apps to apps & {{name:"iHosts", ac_power:true, online:true}}
set apps to apps & {{name:"Evernote", ac_power:true, online:true}}
set is_ac_power to run script (POSIX file "/Users/IceHe/Documents/AppleScript/Lib/is_ac_power.scpt")
set is_online to run script (POSIX file "/Users/IceHe/Documents/AppleScript/Lib/is_network_available.scpt")
repeat with each_app in apps
set is_allowed to true
try
if (online of each_app) ≠ is_online then
set is_allowed to false
end if
on error
end try
try
if (ac_power of each_app) ≠ is_ac_power then
set is_allowed to false
end if
on error
end try
if is_startup then
if is_allowed and not (run script (POSIX file "/Users/IceHe/Documents/AppleScript/Lib/is_app_running.scpt") with parameters {name of each_app}) then
tell application (name of each_app) to launch
end if
else
if not is_allowed and (run script (POSIX file "/Users/IceHe/Documents/AppleScript/Lib/is_app_running.scpt") with parameters {name of each_app}) then
tell application (name of each_app) to quit
end if
end if
end repeat
if is_startup then
set target_app to "iStat Menus"
if (run script (POSIX file "/Users/IceHe/Documents/AppleScript/Lib/is_app_running.scpt") with parameters target_app) and (run script (POSIX file "/Users/IceHe/Documents/AppleScript/Lib/is_app_on_dock.scpt") with parameters target_app) then
tell application target_app to quit
end if
end if
end run
Show Comments