Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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!

share|improve this question
    
In cron ~ is not understood use thefull pathname –  Mark May 8 '13 at 16:08
    
@Mark It works for me in both the user's crontab and /etc/crontab. –  Lauri Ranta May 8 '13 at 18:25
add comment

2 Answers

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.

share|improve this answer
    
But won't fix the issue –  Mark May 8 '13 at 16:43
add comment

The entries have to be on a single line. If you use /etc/crontab, the sixth field has to be the username:

0 9,17 * * * yourusername osascript ~/Documents/disablemail.scpt

You can edit the user's crontab with crontab -e (or EDITOR=pico crontab -e). The entries can't include username fields:

0 9,17 * * * osascript ~/Documents/disablemail.scpt
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.