Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to set up a python script to run every weekday(not sunday and saturday) on my mac OSX 10.8.4. From what I have found so far, it looks like I want to use cron. But before I do something horrible to my computer can someone please confirm this will do what I want?

>>> crontab -e
>>> 30 4 * * 1-5 python /Users/lego90511/PycharmProjects/Stock Scanner/stock_scanner.py

If this some how does work please tell me, how can I then remove it from chron?

share|improve this question
add comment

2 Answers

That should work, but replace Stock Scanner with Stock\ Scanner. You can undo the changes by running crontab -e and just deleting the line. If you haven't changed EDITOR and you don't know how to use vi, you can use EDITOR=nano crontab -e.

So basically run crontab -e (or EDITOR=nano crontab -e) and add a line like this:

30 4 * * 1-5 python ~/PycharmProjects/Stock\ Scanner/stock_scanner.py

The crontab format is described in man 5 crontab.

Using launchd, you could save a plist like this as ~/Library/LaunchAgents/test.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>test</string>
  <key>ProgramArguments</key>
  <array>
    <string>python</string>
    <string>/Users/lego90511/PycharmProjects/Stock Scanner/stock_scanner.py</string>
  </array>
  <key>StartCalendarInterval</key>
  <array>
    <dict>
      <key>Weekday</key>
      <integer>1</integer>
      <key>Hour</key>
      <integer>4</integer>
      <key>Minute</key>
      <integer>30</integer>
    </dict>
    <dict>
      <key>Weekday</key>
      <integer>2</integer>
      <key>Hour</key>
      <integer>4</integer>
      <key>Minute</key>
      <integer>30</integer>
    </dict>
    <dict>
      <key>Weekday</key>
      <integer>3</integer>
      <key>Hour</key>
      <integer>4</integer>
      <key>Minute</key>
      <integer>30</integer>
    </dict>
    <dict>
      <key>Weekday</key>
      <integer>4</integer>
      <key>Hour</key>
      <integer>4</integer>
      <key>Minute</key>
      <integer>30</integer>
    </dict>
    <dict>
      <key>Weekday</key>
      <integer>5</integer>
      <key>Hour</key>
      <integer>4</integer>
      <key>Minute</key>
      <integer>30</integer>
    </dict>
  </array>
</dict>
</plist>

Then load the plist by running launchctl load ~/Library/LaunchAgents/test.plist or by logging out and back in. You can apply changes to the plist by unloading and loading it.

Note that both cron and launchd use a 24-hour clock. If you meant 4 PM instead of 4 AM, replace the hour values with 16.

share|improve this answer
add comment

Take a look at Hazel.

This is an app I use for all of my automation needs. I highly recommend it.

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.