I used this script to always keep either Boxee or Hulu Desktop running. As soon as one is quit the other launches. Handy for using a computer as a home theatre PC.
Here’s the script:
global appIndex, appList
set appList to {"Boxee", "Hulu Desktop"}
-- close running apps at start to get clean start
repeat with theApp in appList
quit_app(theApp)
end repeat
set appIndex to 0
repeat
if not is_running(appList) then
open_app(appItem())
set appIndex to ((appIndex + 1) mod 2)
quit_app(appItem())
end if
delay 1
end repeat
on appItem()
return item (appIndex + 1) of appList
end appItem
on is_running(theAppList)
tell application "System Events" to set processList to (name of processes)
repeat with theApp in theAppList
if processList contains theApp then return true
end repeat
return false
end is_running
on open_app(theApp)
do shell script "open -a \"" & theApp & ".app\""
end open_app
on quit_app(theApp)
set appId to 0
try
tell application "System Events" to set appId to unix id of application process theApp
end try
if (appId > 0) then
do shell script "kill " & appId
end if
end quit_app

