I was searching for a way to automatically scan my Music folder with iTunes on a regular basis to keep my Library up to date. What seemed like an easy enough task turned into a nightmare of a trip - mainly because of the weird interaction between cron and Applescript.
My goal was to write a simple cron task that called a simple AppleScript stored in a text file or compiled script. The AppleScript was easy enough - but getting it to run in cron was a DOG!!! I don't know exactly what the interaction is between cron and osascript - but it ain't pretty. I spent hours researching other peoples efforts and finally came up with a viable solution.
Read the rest of the article for the details...
The solution involves turning on the "Accept Remote AppleEvents" in the sharing control panel. Thats the first step. Next step is to create the text file containing the script. Create a text file (I used BBEdit), save with UNIX linendings and enter:
#!/bin/sh[Note: The "tell" line has been broken in two for easier reading; enter it as one line]. Replace VOLNAME and the path with the volume and path to your music folder(s). Save the text file to your choice of locations - I chose the Scripts menu directory. Then set the permissions to executeable:
osascript <<EOF
using terms from application "iTunes" of machine "eppc://127.0.0.1"
tell application "iTunes" of machine "eppc://127.0.0.1" to add
{"VOLNAME:Path:to:Music:"} to playlist "Library"
end using terms from
EOF
chmod 755 filenameNow edit your crontab or the System's crontab to run the script every hour, 15 mins, or whateever you want:
* 1 * * * sh "/path/to/text/file/saved/above"Thats it!
osascript <<EOFwould cause the iTunes on the remote machine to play the next track. I won't expoundon this anymore as it has been covered in the forums and over at MacNN forums. Have a look - lots of possibilities here.
-> using terms from application "iTunes" of machine "eppc://127.0.0.1"
-> tell application "iTunes" of machine "eppc://127.0.0.1" to play the current track
-> end using terms from
-> EOF
Mac OS X Hints
http://hints.macworld.com/article.php?story=20020427100608542