Start any program at a given time range.

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Start any program at a given time range. Fri Jul 16, 2010 10:39 pm • by chavanak
Hi,
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
chavanak
 
Posts: 2
Joined: Thu Jun 03, 2010 9:09 am

Re: Start any program at a given time range. Sat Jul 17, 2010 1:32 am • by sjk
Interesting use of Hazel for this and Better battery life instead of launchd or cron. :)
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene


Return to Tips & Tricks - DO NOT POST QUESTIONS