Created
March 3, 2012 09:46
-
-
Save osdrv/1965255 to your computer and use it in GitHub Desktop.
elections_viewer.scpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on appIsRunning(appName) | |
tell application "System Events" to (name of processes) contains appName | |
end appIsRunning | |
on killAppRunning(appName) | |
try | |
tell application "System Events" | |
set pid to unix id of process (appName) as Unicode text | |
do shell script "kill " & pid | |
end tell | |
end try | |
end killAppRunning | |
set the_app to "elections_viewer" | |
set the_state to "" | |
set should_refresh to false | |
repeat while (true) | |
delay 1 | |
if should_refresh then | |
tell application the_app to activate | |
set should_refresh to false | |
end if | |
if not appIsRunning(the_app) then | |
tell application the_app to activate | |
end if | |
set v to "" | |
try | |
tell application the_app to set v to version | |
end try | |
if v is "" then | |
killAppRunning(the_app) | |
end if | |
tell application "System Events" | |
try | |
set pid to unix id of process (the_app) as Unicode text | |
set the_state to paragraph 2 of (do shell script "ps -p " & quoted form of pid & " | awk '{ print $3 }'") | |
end try | |
end tell | |
if the_state = "Z" then | |
killAppRunning(the_app) | |
set should_refresh to true | |
end if | |
end repeat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment