Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

UI Scripting iTunes

When right-clicking on some tracks in iTunes "Convert ID3 Tags..." appears in the contextual menu.


I can't find any mention of this in the iTunes dictionary, so I think I'll have to revert to UI scripting - but I have no idea where to start!


I've used UIElementInspector to get me the following, but I don't know how to interpret it to get to the dialog.


<AXApplication: “iTunes”>

<AXWindow: “iTunes”>

<AXMenu>

<AXMenuItem: “Convert ID3 Tags…”>


Attributes:

AXRole: “AXMenuItem”

AXRoleDescription: “menu item”

AXParent: “<AXMenu>”

AXEnabled: “1”

AXPosition: “x=777 y=755”

AXSize: “w=179 h=18”

AXTitle: “Convert ID3 Tags…”

AXHelp: “(null)”

AXSelected (W): “1”

AXMenuItemCmdChar: “(null)”

AXMenuItemCmdVirtualKey: “(null)”

AXMenuItemCmdGlyph: “(null)”

AXMenuItemCmdModifiers: “0”

AXMenuItemMarkChar: “(null)”

AXMenuItemPrimaryUIElement: “(null)”


Actions:

AXCancel - cancel

AXPress - press


Once I get the dialog box up, I need to check the ID3 tag version box, leave the popup to the default, None, and click OK.


This is the UIElementInspector for the dialog:


<AXApplication: “iTunes”>

<AXWindow: “Convert ID3 Tags”>


Attributes:

AXRole: “AXWindow”

AXRoleDescription: “dialog”

AXSubrole: “AXDialog”

AXTitle: “Convert ID3 Tags”

AXFocused: “1”

AXParent: “<AXApplication: “iTunes”>”

AXChildren: “<array of size 12>”

AXPosition (W): “x=650 y=208”

AXSize: “w=380 h=280”

AXMain (W): “1”

AXMinimized: “0”

AXCloseButton: “(null)”

AXZoomButton: “(null)”

AXMinimizeButton: “(null)”

AXToolbarButton: “(null)”

AXFullScreenButton: “(null)”

AXProxy: “(null)”

AXTitleUIElement: “<AXStaticText>”

AXGrowArea: “(null)”

AXDefaultButton: “<AXButton: “OK”>”

AXCancelButton: “<AXButton: “Cancel”>”

AXDocument: “(null)”

AXModal: “1”

AXFullScreen: “0”

AXIdentifier: “_NS:10”


Actions:

AXRaise - raise


Any help would be gratefully received.


Thanks!

MacBook Pro, OS X Mountain Lion, 13" Late 2011 8GB RAM

Posted on Aug 17, 2012 8:25 AM

Reply
Question marked as Best reply

Posted on Aug 17, 2012 12:01 PM

Applescript can't do that, it is harder that you think and you should give up now. Instead, get started by using a shell tool "id3tool":

# See if ''id3tool'' is already installed with this Terminal command: id3tool # If no such command, install it: curl -O http://nekohako.xware.cx/id3tool/id3tool-1.2a.tar.gz gnutar -xzf id3tool-1.2a.tar.gz cd ~/id3tool-1.2a # Now use these commands to compile and install the program: ./configure make sudo make install # You need to enter your password to continue. # Now see if it is installed: id3tool which id3tool # This final command gives you the filesystem location of the command. # When id3tool is installed, you can dump the contents of all ''id3v1'' tags in your iTunes Music folder: cd ~/Music/ find . -name *.mp3 2> /dev/null -print0 | xargs -0 id3tool # You probably want to dump the tag contents to a text file for easier viewing or future reference: find . -name *.mp3 2> /dev/null -print0 | xargs -0 id3tool > -Tags.txt open ./-Tags.txt

This instruction is given as an exercise, in reality iTunes doesn't use the ancient version 1 tags. Most people have no idea of all the crud lurking inside their music files in obsolete tags, some of it embarrassing or incriminating.


id3tool can only read tags, it can't change them. If you get this far and want to know how to manipulate the newer version of tags iTunes uses, respond here and I will explain more.


EDIT:

I forgot to say that in order to install shell tools you probably need to have Xcode installed.


Message was edited by: Gnarlodious

11 replies
Question marked as Best reply

Aug 17, 2012 12:01 PM in response to Arkouda

Applescript can't do that, it is harder that you think and you should give up now. Instead, get started by using a shell tool "id3tool":

# See if ''id3tool'' is already installed with this Terminal command: id3tool # If no such command, install it: curl -O http://nekohako.xware.cx/id3tool/id3tool-1.2a.tar.gz gnutar -xzf id3tool-1.2a.tar.gz cd ~/id3tool-1.2a # Now use these commands to compile and install the program: ./configure make sudo make install # You need to enter your password to continue. # Now see if it is installed: id3tool which id3tool # This final command gives you the filesystem location of the command. # When id3tool is installed, you can dump the contents of all ''id3v1'' tags in your iTunes Music folder: cd ~/Music/ find . -name *.mp3 2> /dev/null -print0 | xargs -0 id3tool # You probably want to dump the tag contents to a text file for easier viewing or future reference: find . -name *.mp3 2> /dev/null -print0 | xargs -0 id3tool > -Tags.txt open ./-Tags.txt

This instruction is given as an exercise, in reality iTunes doesn't use the ancient version 1 tags. Most people have no idea of all the crud lurking inside their music files in obsolete tags, some of it embarrassing or incriminating.


id3tool can only read tags, it can't change them. If you get this far and want to know how to manipulate the newer version of tags iTunes uses, respond here and I will explain more.


EDIT:

I forgot to say that in order to install shell tools you probably need to have Xcode installed.


Message was edited by: Gnarlodious

Aug 17, 2012 12:11 PM in response to Gnarlodious

Thanks for your input.


The problem I am trying to rectify is precisely the crap that's lurking around inside files, so I do need some way of stripping it away. (I believe) it's a side-effect of this that has thrown the local version of my iTunes Match directories into disarray.


In summary, I have data that I don't want attached to a load of files for which iTunes Match can't find a match and I want rid of it!


(By way of further explanation: I have a local master of all my iTunes data that's also synced with iTunes Match. i.e. all the files that got a match were deleted locally and downloaded again from the cloud. At some indeterminate point, files that were NOT matched started to show up in the local master in different - nonsense - albums and this was reflected in the underlying directory structure. Looking more closely at those files which had moved, I discovered that they had corresponding nonsense ID3 tags. (I found that by stumbling on the Convert ID3 Tags... command which showed them in all their nonsense in iTunes. So, executing the command finding the eroneous album and/or genre data moves them back to their correct album.)


The problem is that I have a series of 82 albums with these issues so I am seeking to automate the task. I have myriad backups of the correct directory structure, so I have restored that and don't have to work out the correct album name, but I can't find the point at which the scrambling happened, so I can't simply apply the iTunes Library file backup - and even if I could the problem would likely recur.)

Aug 17, 2012 12:17 PM in response to Gnarlodious

After running the above commands, you will get a text file containing all the IDv1 tags in all your MP3 files.


Even though it's obsolete for iTunes, ''id3v1'' tags seem to still be used. Older MP3 desktop players and in-dash units use ''id3v1'' tags to display song and artist while playing MP3 disks. You can remove the old tags entirely, or leave them in with the proper information so it will display in these older disk players.


If your file doesn't even have the id3v1 tag, you will see output like this:


Filename: ~/iTunes Music/Air/Moon Safari/01 La Femme d'Argent.mp3

No ID3 Tag


A minimal tag ready for MP3 players would look like this:


Filename: ~/iTunes Music/Al Stewart/Past, Present and Future/06 Roads to Moscow.mp3

Song Title: Roads to Moscow

Artist: Al Stewart

Tags with useless cruft from illegal downloads might look like this:


Filename: ~/iTunes Music/Dark Moor/Dark Moor/07 Attila_ Overture.mp3

Song Title: Attila Overture

Artist: Dark Moor

Album: Dark Moor

Note: Ripped by wish*master-tw

Track: 7

Year: 2003

Genre: Metal (0x9)


For the purpose of CD players, any data beyond artist and title is superfluous, since iTunes doesn't use these old tags anyway. My solution was to delete them entirely and put the new data in minus the cruft. Or optionally you can just leave out the id3v1 and put your data in a newer format of tag. But to do that you need to install more shell tools.

Aug 17, 2012 2:14 PM in response to Arkouda

Hi Bernard,


Maybe you might want to try the following GUI script. This beta version assumes your iTunes window is open in list view and a track is selected.


Unfortunately, I was unable to avoid using Cliclick.


tell application "iTunes"

activate

if selection is {} then return

tell application "System Events"

tell process "iTunes"

set theSelectedRow to row 1 of outline 1 of scroll area 3 of window "iTunes" whose selected is true

set {x, y} to position of theSelectedRow

key down control

tell me to do shell script "/usr/local/bin/cliclick " & x & space & y

key up control

keystroke "Convert ID3 Tags" & return

delay 1

if (not (exists window "Convert ID3 Tags")) then return

click checkbox 1 of window "Convert ID3 Tags"

click button "OK" of window "Convert ID3 Tags"

end tell

end tell

end tell


Hope it can help.


Message was edited by: Pierre L. (replaced “Convert” with “Convert ID3 Tags”)

Aug 17, 2012 4:28 PM in response to Pierre L.

Hi Pierre


I guessed you would know how to do it! Thank you!!


I had to make a small change (below) to the shell script that calls cliclick, but it does work. (This might just be that we are using different versions of cliclick and the sytax has changed?)


The only question that I have (for now) is how can I iterate through several rows in the selection? (Can I use UI scripting to set the selection to the next row in a list?)


tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y


-Bernard





Aug 17, 2012 4:43 PM in response to Arkouda

Hi Pierre


I figured it out, so here's the final working version. Can you copy n paste and reply so that I can give you your solver's kudos?


Thanks again.


-Bernard




tell application "iTunes"


activate

if selection is {} then return

set theSelection to selection

repeat with aTrack in theSelection


revealaTrack

tell application "System Events"

tell process "iTunes"

set theSelectedRow to (row 1 of outline 1 of scroll area 3 of window "iTunes" whose selected is true)

set {x, y} to position of theSelectedRow


key downcontrol

tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y


key upcontrol

keystroke "Convert" & return

delay 1

if (not (exists window "Convert ID3 Tags")) then return

click checkbox 1 of window "Convert ID3 Tags"

click button "OK" of window "Convert ID3 Tags"

end tell

end tell

end repeat

end tell

Aug 17, 2012 9:01 PM in response to Arkouda

Many thanks, Bernard, for your feedback.


You're right, I was using an old version of Cliclick. I've now dowloaded version 2.0, made available yesterday.


There's one small issue with the last version of the script: it doesn't work when the selection contains tracks that don't have any ID3 tags. The following version fixes that issue (using an if clause) and also incorporates some other very minor changes.


tell application "iTunes"

activate

if selection is {} then return

set theSelection to selection

repeat with thisTrack in theSelection

reveal thisTrack

tell application "System Events"

tell process "iTunes"

set {x, y} to position of (row 1 of outline 1 of scroll area 3 of window "iTunes" whose selected is true)

key down control

tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y

key up control

keystroke "Convert ID3 Tags" & return

delay 1

if (exists window "Convert ID3 Tags") then

click checkbox 1 of window "Convert ID3 Tags"

click button "OK" of window "Convert ID3 Tags"

end if

end tell

end tell

end repeat

end tell


P.-S. May I dare suggest that you use any other color than red in your future posts. 😉


Message was edited by: Pierre L.

Aug 17, 2012 9:49 PM in response to Arkouda

It sounds like you managed to transfer the old id3v1 tags to the new id3v2 tags that iTunes uses. But iTunes can't remove id3v1 tags, it can only transfer existing data while leaving the old tags there. The shell tool id3lib has what you need to edit those tags:


curl -O http://iweb.dl.sourceforge.net/project/id3lib/id3lib/3.8.3/id3lib-3.8.3.tar.gz gnutar -xzf id3lib-3.8.3.tar.gz cd id3lib-3.8.3 ./configure make sudo make install # You need to enter your password to continue. # Now see if it is installed: id3tag which id3tag # This final command gives you the filesystem location of the command. This script installed 4 commands: id3convert -help id3cp -h id3info -h id3tag -h


However, id3lib can't delete tags. To totally remove the obsolete id3v1 tags install the shell tool id3v2:


curl -O http://hivelocity.dl.sourceforge.net/project/id3v2/id3v2/0.1.11/id3v2-0.1.11.tar.gz gnutar -xzf id3v2-0.1.11.tar.gz cd id3v2-0.1.11 make sudo make install # You need to enter your password to continue. # Now see if it is installed: id3v2 which id3v2


The id3v2 command uses the id3lib library, so they both need to be installed. Note that the following command only removes MP3 "id3v1" tags, it does not touch the "id3v2" tags that iTunes uses. It is strongly recommended to back up your MP3 files before running any file modifying scripts! First make sure you are in the "iTunes Music" folder as your working directory:


cd ~/Music/iTunes\ Music # May vary as to your installation! # Delete all id3v1 tags with this command: find . -name *.mp3 -print0 | xargs -0 id3v2 -s


If you dump the contents of all version 1 tags you may see all sort of oddball data fields that software added over the years. These fields cannot be individually deleted, you can only delete the entire id3v1 tag and write a new tag adding the fields you want. In addition, id3v1 tags only support something like 30 characters, so long strings will be truncated. For these reasons, it is usually best to leave the id3v1 tag out of the file unless you want it there for backwards compatibility.


After doing all this, you can run the command line I gave earlier and you should see all your old MP3 tags have been removed. In another post I'll explain how to scriptomatically edit the id3v2 tags.

UI Scripting iTunes

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.