Applescripting iTunes Help

Discussion in 'Mac Programming' started by wrldwzrd89, Apr 15, 2007.

  1. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #1
    Alright, I have the following script, which operates on iTunes tracks that have no ID3 tags, and whose names are numbers:

    Code:
    tell application "iTunes"
    	if selection is not {} then
    		set sel to selection
    	else
    		display dialog "You must select some tracks first..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
    	end if
    	
    	set oldfi to fixed indexing
    	set fixed indexing to true
    	
    	repeat with aTrack in sel
    		set theName to do shell script "cat /Users/wrldwzrd89/Documents/Computers/UNIX/Scripts/VGMix/data/autotags/songname/" & aTrack & ".songname"
    		set theArtist to do shell script "cat /Users/wrldwzrd89/Documents/Computers/UNIX/Scripts/VGMix/data/autotags/artist/" & aTrack & ".artist"
    		set theAlbum to do shell script "cat /Users/wrldwzrd89/Documents/Computers/UNIX/Scripts/VGMix/data/autotags/album/" & aTrack & ".album"
    		tell aTrack
    			
    			set name to theName
    			set artist to theArtist
    			set album to theAlbum
    			set comment to "www.vgmix.com"
    			set genre to "Game"
    			
    		end tell
    	end repeat
    	
    	set fixed indexing to oldfi
    	
    	try
    		if frontmost is true then display dialog "Done!" buttons {"Thanks"} ¬
    			default button 1 with icon 1 giving up after 15
    	end try
    	
    end tell
    However, it fails on line 12 with a strange error message, complaining about being unable to convert something of some weird class to string. Anyone know why this isn't working?
     
  2. wrldwzrd89 thread starter macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #2
    Found the problem, and fixed it. Moving the do shell script stuff inside the tell aTrack block and using name instead of aTrack made it work.

    Fixed code, for anyone who wants it:

    Code:
    tell application "iTunes"
    	if selection is not {} then
    		set sel to selection
    	else
    		display dialog "You must select some tracks first..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
    	end if
    	
    	set oldfi to fixed indexing
    	set fixed indexing to true
    	
    	repeat with aTrack in sel
    
    		tell aTrack
    			set theName to do shell script "cat /Users/wrldwzrd89/Documents/Computers/UNIX/Scripts/VGMix/data/autotags/songname/" & name & ".songname"
    		        set theArtist to do shell script "cat /Users/wrldwzrd89/Documents/Computers/UNIX/Scripts/VGMix/data/autotags/artist/" & name & ".artist"
    		        set theAlbum to do shell script "cat /Users/wrldwzrd89/Documents/Computers/UNIX/Scripts/VGMix/data/autotags/album/" & name & ".album"
    			set name to theName
    			set artist to theArtist
    			set album to theAlbum
    			set comment to "www.vgmix.com"
    			set genre to "Game"
    			
    		end tell
    	end repeat
    	
    	set fixed indexing to oldfi
    	
    	try
    		if frontmost is true then display dialog "Done!" buttons {"Thanks"} ¬
    			default button 1 with icon 1 giving up after 15
    	end try
    	
    end tell
     

Share This Page