I use Flux during night times to work easily on my mac. Flux changes the color temperature of the display and will make it less taxing on your eyes. But Flux is only useful after 18:00 and up to 6:00 in the morning. So I use hazel again to start Flux at a particular time and quit the program in the morning. Here is the code.
- Code: Select all
set t to (time string of (current date))
set Pos to offset of ":" in t
set theHour to characters 1 thru (Pos - 1) of t as string
set t to characters (Pos + 1) through end of t as string
set Pos to offset of " " in t
set theSfx to characters (Pos + 1) through end of t as string
set y to (theHour)
set ampm to (theSfx)
tell application "System Events" to set FluxRunning to (name of processes) contains "Flux"
if y is greater than "5" and ampm contains "PM" and FluxRunning is false then
tell application "Flux" to activate
end if
if y is greater than "5" and ampm contains "AM" and FluxRunning is true then
tell application "Flux" to quit
end if
Hazel rule goes as follows:
if name is Flux (an empty file by name Flux is present in my Misc directory) and date last matched is not in the last 1 hour; run the above script.
You can change the timing of this rule to your liking. Also, you can quit/open multiple applications at the desired time

Hope you find this script useful

Cheers,
Chav