I'm trying to write an AppleScript to do bulk find-and-replace operations on iTunes track names. Currently, this is my code:
tell application "iTunes" set sel to selection of front browser window if sel is {} then try display dialog "Nothing is selected…" buttons {"Quit"} with icon 0 end try return end if set c to (count of sel) set theSearchString to display dialog "Find:" default answer "" --prompt for input to search for set theReplacementString to display dialog "Replace with:" default answer "" --prompt for input to search for repeat with i from 1 to c --set the movement numbers set thisTrack to item i of sel set songName to (get name of thisTrack) set name of thisTrack to (findAndReplaceInText(songName, text returned of theSearchString, text returned of theReplacementString)) end repeat end tell on findAndReplaceInText(theText, theSearchString, theReplacementString) set AppleScript's text item delimiters to theSearchString set theTextItems to every text item of theText set AppleScript's text item delimiters to theReplacementString set theText to theTextItems as string set AppleScript's text item delimiters to "" return theText end findAndReplaceInText
Currently, the findAndReplaceInText()
function returns error 1708. What did I do wrong? The find-and-replace function is coming from Apple: Mac Automation Scripting Guide- Manipulating Text