I'm trying to get something similar to work too (using the
My WiFi access point is misbehaving, and sometimes restarts. When it does that, many of my MacOS systems do not automatically reconnect, and this is very inconvenient for my Mac mini that does not have a keyboard, mouse, or ethernet attached.
From the networksetup "man" page (
The networksetup command requires at least
admin privileges to change network settings. If the "Require an administrator password to access system-wide preferences" option is selected in System Preferences >
Security & Privacy, then root privileges are required to change network settings.
But I expect there's something different about the context in which cron runs a user's job than when it runs whilst logged into the desktop.
In my case, when it fails it outputs the following:
Error: -3930 The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3930.)
and the only place I can find error "3930" documented is in Jonathan Levin's "new OS X Book" notes, unfortunately "Operation not permitted" isn't much to go on.
Perhaps Marc is indeed thinking in the right direction, at least that if not running interactively as a "Desktop" user then it needs to run as root. Going to try that, next, and report back...
When I looked more closely at my logs I saw that it had successfully re-associated to the network at least once or twice before failing with the above error: to reiterate, that was when running from my own user crontab.
But, I did switch to running it from root’s crontab and it has worked successfully several times since then. So I’d definitely suggest trying that (
sudo crontab -e being the way I went about doing that).