Skip to content

Instantly share code, notes, and snippets.

@antimodular
Created November 14, 2015 12:08
Show Gist options
  • Save antimodular/6b6c17789cc09a1bfc17 to your computer and use it in GitHub Desktop.
Save antimodular/6b6c17789cc09a1bfc17 to your computer and use it in GitHub Desktop.
--config nightly shutdown time
set shutdown_hour to 23
set shutdown_min to 35
set shutdown_sec to 0
global shutdown_time
set shutdown_time to shutdown_hour * 60 * 60 + shutdown_min * 60 + shutdown_sec
--config screen arrangement adjust
global posixDisplayFixPath
set posixDisplayFixPath to "/Applications/of_v0.9.0RC1_osx_release/addons/ofxDisplayLayout/displayFix/bin/displayFix.app"
global displayFixDidRun
set displayFixDidRun to false
set displayFix_hour to 9
set displayFix_min to 30
set displayFix_sec to 0
global displayFix_time
set displayFix_time to displayFix_hour * 60 * 60 + displayFix_min * 60 + displayFix_sec
--config restart app watch dog
--set posixCalculatorPath to "/Applications/of_v0.9.0RC2_osx_release/apps/zoomP/zoom_pavilion_33_core/bin/zoom_pavilion.app/Contents/MacOS/zoom_pavilion"
global posixMainAppPath
set posixMainAppPath to "/Applications/of_v0.9.0RC2_osx_release/apps/zoomP/zoom_pavilion_35/bin/zoom_pavilion.app"
global attemptCount
set attemptCount to 0
--config force quit watch dog
global posixHearbeatPath
set posixHearbeatPath to "/Applications/of_v0.9.0RC2_osx_release/apps/zoomP/zoom_pavilion_35/bin/data/heartbeat.txt"
global lastModTime
set lastModTime to "Deltron 3030"
--delay (5)
on idle
--repeat
---------------restart app watch dog---------------
tell application "System Events"
set isMyAppRunning to (count of (every process whose bundle identifier is "cc.openFrameworks.ofapp")) > 0
--display dialog "isMyAppRunning " & isMyAppRunning
end tell
if isMyAppRunning is false then
log "app is not present. let's restart it."
--delay 5
beep
set attemptCount to attemptCount + 1
log ("attemptCount is " & attemptCount)
tell application posixMainAppPath to activate
else
log "we hope app is running fine or process is zombi"
end if
if (attemptCount is equal to 5) then
my checkPulseFile()
end if
my checkNightly()
if displayFixDidRun is false then
my checkDisplayFixTime()
end if
delay (10)
--end repeat
end idle
to checkPulseFile()
--check when log file was updated last
tell application "System Events"
set newModifyTime to modification date of file posixHearbeatPath
end tell
if newModifyTime is equal to lastModTime then
--do shell script "shutdown -r now" user name username password passwrd with administrator privileges
log "app is not updating its log file. let's kill it."
beep
beep
beep
do shell script {"killall -9 zoom_pavilion"}
else
set lastModTime to newModifyTime
log "log file being updated properly"
end if
set attemptCount to 0
end checkPulseFile
to checkNightly()
---------------nightly shutdown time---------------
set current_time to (time of (current date))
if current_time is greater than shutdown_time then
--display dialog shutdown_time
log "it's the end of day. let's exit this script"
beep
quit
--display dialog "quit"
else
--display dialog t & " != " & shutdown_time
--display dialog shutdown_time
--display dialog current_time
end if
end checkNightly
to checkDisplayFixTime()
---------------nightly shutdown time---------------
set current_time to (time of (current date))
if current_time is greater than displayFix_time then
log "reached displayFix arrangement time"
beep
tell application posixDisplayFixPath to activate
set displayFixDidRun to true
--display dialog "reached adjust display arrangement time"
else
--display dialog t & " != " & shutdown_time
--display dialog shutdown_time
--display dialog current_time
end if
end checkDisplayFixTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment