How to update iTunes Match from the command line

applescriptcommand lineitunes-match

I use iTunes Match to access my iTunes library at work. I added some new music to my library (back at home) recently, but I forgot to run the "Update iTunes Match" command to ensure that the songs were matched/uploaded to the cloud. Now I'm at work, and my new tunes aren't in iCloud.

I have shell access to my iMac at home using SSH. How can I tell iTunes to update my library from the command line? (I presume the answer will involve the use of osascript.)

A side benefit of knowing this would be that I can schedule it to run nightly so this doesn't happen again, which is why I'd rather not just use VNC.

Best Answer

iTunes doesn't let you AppleScript this natively, but you can use some UI scripting to 'click' the menu bar item and do it for you:

tell application "iTunes" to activate
tell application "System Events"
    tell application process "iTunes"
        click menu item "Update iTunes Match" of menu 1 of menu bar item "Store" of menu bar 1
    end tell
end tell

You can use that via SSH:

osascript -e 'tell application "iTunes" to activate' -e 'tell application "System Events"' -e 'tell application process "iTunes"' -e 'click menu item "Update iTunes Match" of menu 1 of menu bar item "Store" of menu bar 1' -e 'end tell' -e 'end tell'