Hi guys. I figured it out. I used a different way to substitute text
in text edit (by installing TextCommands). I still have to do a fair
bit of manual editing in the DJ program but that has nothing to do
with the script. It now works fine. Thanks alot for everyone's input.
Karo.
My final script:
global allText
global filePath
global fileName
global artistName
global songName
global fileName2
global filePath2
global counter
global flag
global TheLocationText
set counter to 2
repeat with x from 1 to 1810
tell application "TextEdit"
set AppleScript's text item delimiters to "<ENTRY"
set allText to text of document 1
set textItems to text items of allText
set parag to text item counter of textItems
if parag does not contain "ARTIST=" then
set counter to counter + 1
set parag to text item counter of allText
if parag does not contain "ARTIST=" then
set counter to counter + 1
set parag to text item counter of allText
end if
end if
if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText
if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText
if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText
if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText
if parag contains "&" then
set counter to counter + 1
set parag to text item counter of allText
end if
end if
end if
end if
end if
set AppleScript's text item delimiters to "\""
set artistName to text item 2 of parag as text --First match
criteria
set songName to text item 6 of parag as text --Second match
criteria
set AppleScript's text item delimiters to " "
set line2 to text item 2 of parag
set AppleScript's text item delimiters to "\""
set filePath to text item 2 of line2 as text ----that's what needs
to be replaced with value of filePath2
set fileName to text item 4 of line2 as text --that's what also
needs to be replaced with value of fileName2
end tell
tell application "iTunes"
try
set TheTrack to (track 1 of library playlist 1 whose artist is
artistName and the name is songName)
set TheLocation to location of TheTrack as string
set TheLocationText to text of TheLocation
set flag to 1 -- using a flag in case iTunes cannot find a song for
some reason
on error
set flag to 0
end try
end tell
set text item delimiters to ":" -- now a path like
"Disk:Users:kurtp:Music:iTunes" is converted to a path like "Disk/
Users/kurtp/Music/iTunes" which is how my DJ program describes files.
set y to text items of TheLocationText
set r to the count of text items of y
set f to text items 1 through -2 of y
set fileName2 to text item -1 of y
set newPathTemp to "/" & text item 2 of y
set d to 3
repeat with i from 1 to (r - 3)
set newPathTemp to newPathTemp & "/" & text item d of y
set d to d + 1
end repeat
get newPathTemp
set filePath2 to newPathTemp & "/"
tell application "TextEdit"
if flag = 1 then
tell application "TextCommands"
set replace1 to search parag for fileName replacing with fileName2
set replace2 to search replace1 for filePath replacing with
filePath2
set replaceWhole1 to search allText for parag replacing with
replace2
end tell
set text of document 1 to replaceWhole1
else
set flag to 1
end if
end tell
set counter to counter + 1
end repeat
>> Stay informed about: text file nightmare