Like many people, I would like my podcasts delivered to my iPhone before I go to work. While there are many ways of doing it, Apple seems to screw things up every time they release a new MacOS X version.
With me, that version was Yosemite. They essentially broke cron.
So? Lets throw some hardware at it. While I use a Cubietruck, a Raspberry Pi will do just as good! Just make sure it's connected to the network and has ntpd keeping it's clock up to date (Rasbian does this for you).
On the Mac:
- Go into your System Preferences (read: Control Panel), hit the Sharing panel, and turn on "Remote Login". This starts the Mac's SSH server and gives you the command to use to access the Mac. You need the "[email protected]" part.
- Save the two Applescripts below into your ~/Library/Scripts folder using the Script Editor (located in Applications >> Utilities).
- Open up your Applications folder and create a "Local Apps" folder. I put Automator apps there.
- Open up Automator and create a new application called "Restart iTunes" in that new folder you created. Make it do the following steps:
- Quit Application >> iTunes (do not save)
- Pause >> 30 seconds
- Launch Application >> iTunes
Your set up is now complete.
On the Pi:
- Install Avahi on your Pi! This lets you use the ".home" domain and will find your Mac. For Raspbian it is:
sudo apt-get install avahi-daemon
- Make a ~/bin directory if you don't have it already:
mkdir ~/bin
- Switch into it:
cd ~/bin
- Make a new file with the below shell script:
nano -w PiTunesSync.sh
- Make it executable:
chmod 755 PiTunesSync.sh
- Test it out:
./PiTunesSync.sh
You will need to say "yes" to authenticating your Mac to the Pi, and the put in your Mac's password. - Putting the password in is going to get annoying really quickly. Thankfully SSH offers a solution, using a pre-shared key. Start by running:
ssh-keygen
- Just keep hitting Return to accept the defaults. You don't even want a password on this key.
- Switch to the SSH config directory:
cd ~/.ssh
- A "id_rsa.pub" file was created here. Copy it to the mac using SSH's SCP:
scp id_rsa.pub [email protected]:.
*The extra :. at the end of the command is needed! And once again, use your Mac's password.``` - Switch back "home":
cd
Back on the Mac:*
- Open up a Terminal (I use iTerm myself, but Apple's own Terminal in Applications >> Utilities will do).
- Make a .ssh folder if there isn't one (it won't show in Finder):
mkdir .ssh
- Append the new key to a "authorized_keys" file in ".ssh":
cat id_rsa.pub >> .ssh/authorized_keys
If it didn't exist, it will now!
And finally, back on the Pi:
- Give it another test:
~/bin/PiTunesSync.sh
This should not prompt you anymore! - Open up your crontab and append the following lines. To open it, run:
crontab -e
# Pull podcasts and sync at 5:50am every day:
50 5 * * * /home/tygris/bin/PiTunesSync.sh >> /home/tygris/pts.log 2>&1
You can adjust the "50" and "5" to when you want it to sync. It's in Millitary time, though, so 1:05pm is really 1305, and in cron is "5 13". For a better explination, man 5 crontab
will give you the full details.