MacOS – Running Applescript using cron jobs not working

applescriptcronmacosmail.app

I'm new to conjobs and applescript but I have the script done correctly i believe. (any critique is welcome) I don't want to bloat my calendar with events to do this because I use my calendar for appointments and I don't need the bloat.

Here's my goal: run an apple script at 9am/5pm to enable/disable a mail account (after this works I'm going to add loging in/out of an Messenger account, first things first)

here's my script:

tell application "Mail"
set offTime to 17
set onTime to 9

      set dayOfWeek to weekday of (current date)
      set theHour to get the (hours of (current date)) as string

      if theHour ≥ onTime then
                say "email on"
                set enabled of account "MAILBOX" to true

      else if theHour ≥ offTime or (dayOfWeek = Saturday or dayOfWeek = Sunday) then
                say "email Off"
                set enabled of account "MAILBOX" to false


      end if

end tell

accessing cron jobs via this

sudo pico /etc/crontab

and within cron jobs i've used

0 9 * * * username osacript
"/Documents/disablemail.scpt"

0 17 * * * username osacript
"/Documents/disablemail.scpt"

variations I've attempted (based on search engine results)

0 9 * * * username osacript
"~/Documents/disablemail.scpt"

0 9 * * * /Documents/disablemail.scpt

0 9 * * * ~/Documents/disablemail.scpt

0 9 * * * osacript /Documents/disablemail.scpt

0 9 * * * osacript ~/Documents/disablemail.scpt

I think that's all of them.

Any feedback/assitance appreciated, thanks!

Best Answer

Cron was replaced by launchd a while back. If you're just getting started with this project, you might want to do it in launchd.