Estoy tratando de escribir un AppleScript para hacer operaciones de búsqueda y reemplazo masivo de nombres de canciones de iTunes. Actualmente, este es mi código:
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
Actualmente, el findAndReplaceInText()
La función devuelve el error 1708. ¿Qué he hecho mal? La función de buscar y reemplazar viene de Apple: Guía de scripts de automatización de Mac - Manipulación de texto