Jay Tuley

Posts tagged with applescript

iEatBrainz applescript to add iTunes selection by Jay

I received an email a little earlier asking what iEatBrainz applescript commands would allow you to add songs from an iTunes selection. iEatBrainz only has a applescript dictionary because it’s an Apple Script Studio app with a lot of Obj-C and just a small bit of applescript. However, since the applescript dictionary encompasses almost all of cocoa, it wasn’t too hard to write a script that takes the currently selected song in iEatBrainz and add it to the tagging list (As long as you know what methods to call).

Open this script in Script Editor

on addSongWithDatabaseID(aDatabaseID, aLibrary, aTaggingController)
    
tell application “iEatBrainz”
        
set aTrack to call method “trackForTrackID:” of aLibrary with parameter (aDatabaseID as string)
        
call method “addiTunesTrack:” of aTaggingController with parameter aTrack
    
end tell
end
addSongWithDatabaseID

tell application “iEatBrainz”
    
set myLibrary to call method “musicLibrary” of call method “mediator” of call method “delegate” of application
    
    set
taggingController to call method “musicMatchings” of call method “mediator” of call method “delegate” of application
end tell

tell
application
“iTunes”
    
set these_tracks to the selection of browser window 1
    —
if no selection
    
if these_tracks is {} then error “No tracks are selected in the front window.”
end tell

repeat with
i from 1 to number of items in these_tracks
    
set this_item to item i of these_tracks
    
tell application “iTunes”
        
set dbID to database ID of this_item
    
end tell
    
addSongWithDatabaseID(dbID, myLibrary, taggingController)
end repeat

This still will have problems on occasion when iEatBrainz gets out of sync with iTunes, due to iTunes renumbering its database.