Created
December 28, 2014 12:01
-
-
Save ofstudio/583de48e902917c1eeec to your computer and use it in GitHub Desktop.
Example of iTunes scripting in OS X with Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example of iTunes scripting in OS X with Javascript | |
* Open /Applications/Script Editor.app, paste the code and click Run button | |
* | |
* @author Oleg Fomin <ofstudio@gmail.com> | |
* | |
*/ | |
var my_app = Application.currentApplication(), | |
itunes = new Application('iTunes'), | |
selection; | |
my_app.includeStandardAdditions = true; | |
itunes.includeStandardAdditions = true; | |
selection = itunes.selection(); | |
if (selection.length > 0) { | |
for (var i in selection) { | |
itunes.play(selection[i]); | |
my_app.displayNotification ( | |
selection[i].artist() + ' is my favorite artist', | |
{ | |
withTitle: 'Cool jukebox', | |
subtitle: 'Now playing: ' + selection[i].name() | |
} | |
); | |
delay(7); | |
} | |
} else { | |
itunes.activate(); | |
itunes.displayDialog('Please select a few tracks in iTunes and try again!'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi oleg. i’m wondering if you’ve tried running any scripts from inside itunes rather than from script editor.
i've made a script that parses discogs.com genres and applies them to selected tracks in itunes. it works fine from inside script editor but when saved and run from itunes, it hangs.
first i save my script to ~/Library/iTunes/Scripts, then in itunes, click on the script icon that appears in the menu bar next to 'help' and select my script. you should see that the js will not work.
the strange thing is that all scripts done in javascript make itunes hang.
this applescript runs fine:
but the equivalent javascript doesn't:
the javascript versions work if run from script editor.
here is my script if you're interested:
https://gist.github.com/north-is-northwest/16fadb1d945cd5c01d9a
it seems very few people have yet used javascript for itunes and there is little documentation. i'm wondering if you've tried this or have any ideas? thanks