Can this be made to repeat?

Hello, I am so very new to this, I know I am way out of my league here.
I am trying to run this script continuously with out having to select a folder where the file is to be saved to.
Also, I want the next song to be selected after the script is ran, then for it to run again.

This was made by Doug Adams
I just want to tweak it a little…


tell application "iTunes"
	
	if selection is not {} and (count items of selection) is 1 then
		set theTrack to item 1 of selection
	else
		my alert_user_and_cancel("Please select one track punk.")
	end if
	
	if class of theTrack is not file track or artworks of theTrack is {} then
		my alert_user_and_cancel("The selected track does not contain Artwork.")
	end if
	
	set artworkFolder to (choose folder with prompt ¬
		"Where do you want to save Artwork?") as string
	
	display dialog "Just a moment..." buttons {""} giving up after 1
	
	try
		set artworkData to (data of artwork 1 of theTrack) as picture
		set artworkFormat to (format of artwork 1 of theTrack) as string
		if artworkFormat contains "JPEG" then
			set extension to ".jpg"
		else if artworkFormat contains "PNG" then
			set extension to ".png"
		end if
		
		set theName to (artist of theTrack & " - " & album of theTrack)
		
		set tempartworkFile to (artworkFolder & "temp" & extension) as string
		set finalartworkFile to (artworkFolder & theName & extension) as string
		
		set file_reference to (open for access tempartworkFile write permission 1)
		write artworkData starting at 0 to file_reference as picture
		close access file_reference
		
		do shell script "cd " & quoted form of (POSIX path of artworkFolder) & ¬
			";tail -c+223 " & quoted form of ("temp" & extension) & "> " & ¬
			quoted form of (theName & extension) & ";rm " & ¬
			quoted form of ("temp" & extension)
		
		(*
		if frontmost then
			if button returned of (display dialog ¬
				"Artwork exported!" buttons {"Show File In Finder", "Thanks"} ¬
				default button 2) is not "Thanks" then
				tell application "Finder"
					reveal file finalartworkFile
					activate
				end tell
			end if
		end if
		*)
		
	on error errM
		close access file_reference
		my alert_user_and_cancel("Unable to export Artwork from the selected track." & ¬
			return & return & errM)
	end try
end tell

to alert_user_and_cancel(message)
	tell application "iTunes" to display dialog message buttons {"Cancel"} ¬
		default button 1 with icon 0
end alert_user_and_cancel


Hi and welcome to MacScripter

try this

set artworkFolder to (choose folder with prompt "Where do you want to save Artwork?") as Unicode text
display dialog "Just a moment..." buttons {""} giving up after 1

tell application "iTunes"
	activate
	set errorCnt to 0
	set artworkCnt to 0
	if selection is {} then
		display dialog "Please select one or more tracks" buttons {"Cancel"} default button 1 with icon 0
	end if
	repeat with theTrack in (get selection)
		try
			if class of theTrack is not file track or artworks of theTrack is {} then error
			set artworkData to (data of artwork 1 of theTrack) as picture
			set artworkFormat to (format of artwork 1 of theTrack) as string
			if artworkFormat contains "JPEG" then
				set extension to ".jpg"
			else if artworkFormat contains "PNG" then
				set extension to ".png"
			end if
			
			set theName to (artist of theTrack & " - " & album of theTrack)
			
			set tempartworkFile to (artworkFolder & "temp" & extension)
			set finalartworkFile to (artworkFolder & theName & extension)
			try
				finalartworkFile as alias -- check if the file exists already
			on error
				set file_reference to (open for access tempartworkFile write permission 1)
				write artworkData starting at 0 to file_reference as picture
				close access file_reference
				
				do shell script "cd " & quoted form of (POSIX path of artworkFolder) & ¬
					";tail -c+223 " & quoted form of ("temp" & extension) & "> " & ¬
					quoted form of (theName & extension) & ";rm " & ¬
					quoted form of ("temp" & extension)
				set artworkCnt to artworkCnt + 1
			end try
		on error
			try
				close access file_reference
			end try
			set errorCnt to errorCnt + 1
		end try
	end repeat
	display dialog (artworkCnt as Unicode text) & " artworks exported" & return & errorCnt & " tracks had no artwork" buttons {"Done"} default button 1
end tell

Stefan … You are the man!!

I selected all the tracks I wanted to export, ran the script, and it worked!
It worked perfect.

Thanks so much.

Dan

Glad to be of help, Dan :slight_smile: