How can I make my Mac (running the most recent OS) do a task automatically once a day? For example, I'd like to have it automatically download a copy of this open source algebraic geometry textbook once a day. I have a feeling that some combination of wget and cron should work, but, after googling and reading the cron documentation, I just couldn't get it to work right.
-
2I suggest you don't use Crontab and instead learn to use Launchd as already suggested. – Martin Marconcini Mar 02 '11 at 12:52
-
My problem is that both cron and launchctl/launchd only permit precise time specs ie. "This hour, minute and second". My Mac is not on all the time - I need something like anacron in the Unix/Linux world, to run tasks "daily" no matter when I wake up and turn on the computer. – q.undertow Jun 01 '22 at 16:12
6 Answers
I think in OS X you should use launchctl for "cron jobs".
But otherwise your task should be easy to do with a cronjob
sudo crontab -e
55 23 * * * wget http://www.math.columbia.edu/algebraic_geometry/stacks-git/book.pdf
This should run everyday at 23:55
Update
You should specify the output location of WGET with -O /path/to/file
- 1,274
- 1
- 10
- 21
-
2If using launchd, see http://apple.stackexchange.com/questions/3030/how-to-run-something-automatically-when-the-system-boots-or-a-use-logs-on – Mar 01 '11 at 23:42
-
2You don't necessarily need sudo. Individual users can have their own crontabs – Doug Harris Jan 05 '12 at 18:16
The cron daemon can be activated by a simple:
sudo touch /private/etc/crontab
Then it's advisable to enter the full path of your /usr/local/bin/wget (or wherever it lives). Cron does not know of your user's $PATH. Hope it helps.
-
This should be the accepted answer, most useful part was "Cron does not know of your user's $PATH", that's very useful and this lead me to solve it on my side. Thanks! – that-ben Nov 22 '23 at 19:32
You may use Cronnix which is a free graphical interface for cron :
- 4,856
-
1cronnix has been officially discontinued upstream. It may stop working correctly (or at all) in recent versions of macOS. – Andrii Abramov Jan 08 '20 at 10:58
If you're finding the command line syntax (etc) too confusing/arcane, you might lok at GUI tool for viewing/editing/creating these jobs.
In the past I've used Lingon, which has been made available on the Mac App Store now too. I don't need to use it very often, but it's very useful when I do!
- 2,130
I recommend Macaroni. Its advantage is that when you set a job to run once a day, it runs whenever your computer is on, regardless of the time. So you won't miss a job because the computer was off at the specified time.
Macaroni is a tool which handles regular maintenance for Mac OS X, including the Mac OS X repair privileges process as well as Unix-style maintenance. You could do this yourself, but don't you have more interesting things to do with your time?
A more elegant solution (than cron) is to use iCal notifications + Applescript.
First, launch AppleScript Editor (located under /Application/Utilities) and paste the following code:
set the destination_file to ("~/Downloads/book.pdf")
set the contentLink to "http://www.math.columbia.edu/algebraic_geometry/stacks-git/book.pdf"
tell application "URL Access Scripting"
download contentLink to destination_file replacing yes
end tell
Save the script and quit applescript editor.
Open your iCal and create a new event for today, setting the time you want, select "repeat: Every day" and as an alarm "Run script" and select your applescript.
If you want to notified for every download, you may add another alarm with a "Message with Sound", "on date".
- 4,856