on run
main()
end run
on main()
set muteVolume to 1 -- a 0 here interferes with the mute command
set middleVolume to 50
set highVolume to 100
set nowTime to time of (current date)
set pmFlag to false
set myPath to POSIX file "/Library/Scripts/Universal Scripts/setSoundVolumePrefs"
tell (do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution") to set {newR, newB} to {word 2 as number, word 4 as number} -- get screen size for monitor
-- newR = 1560 for 27" monitor
if newR > 1700 then set middleVolume to 40 -- 50 was too loud with 27" iMac
script SetSoundVolumePrefs
property WakeUpTime : ""
property SleepTime : ""
end script
try
set SetSoundVolumePrefs to load script file myPath
on error
set WakeUpTime of SetSoundVolumePrefs to text returned of (display dialog "wakeUpTime: (use military format, '6:01') " default answer "" buttons {"OK", "Cancel"} default button "OK")
set SleepTime of SetSoundVolumePrefs to text returned of (display dialog "sleepTime: (use military format, '21:01')" default answer "" buttons {"OK", "Cancel"} default button "OK")
store script SetSoundVolumePrefs in file myPath replacing yes
end try
set WakeUpTime to WakeUpTime of SetSoundVolumePrefs
set SleepTime to SleepTime of SetSoundVolumePrefs
-- convert to numbers
set tees to {WakeUpTime, SleepTime}
set tees to my decoupe(tees)
set {WakeUpTime, SleepTime} to result
if (nowTime is less than SleepTime) and (nowTime is greater than WakeUpTime) then
set soundVolume to middleVolume
else -- After bed time
set soundVolume to muteVolume
end if
set volume output volume (soundVolume)
if soundVolume ≠ muteVolume then
set volume output muted (false)
else
beep
set volume output muted (true)
end if
return
end main
on decoupe(tees) -- t = time
set output to {}
set AppleScript's text item delimiters to ":"
repeat with t in tees
set {h, m} to text items of t
copy ((m as integer) + ((h as integer) * 60)) * 60 to end of output
end repeat
set AppleScript's text item delimiters to "" -- restore
return output
end decoupe