Hello
According to your description, FMP generates a tab-separated-value file, where each field is separated by tab and each record separated by carriage return (CR).
If there's only one field (song path) in each record, the exported text consists of paragraphs each of which corresponds to a song path.
So you may try any of the following codes.
CODE1 is the simplest. AppleScript's paragraph is smart enough to handle all CR, LF, CRLF as delimiters.
CODE2 uses 'using delimiter' parameter of read command.
CODE3 spells out every step to open, read, close in addition to using 'using delimiter' parameter of read command.
--CODE1
set song_file to "HFS:path:to:song_paths.txt"
set pp to paragraphs of (read file song_file) -- System's primary encoding, e.g., Mac-Roman
--set pp to paragraphs of (read file song_file as «class utf8») -- UTF-8
repeat with p in pp
set p to p's contents
if (count p's words) > 0 then -- to skip quasi-blank line, just in case
do shell script "afplay " & quoted form of p
end if
end repeat
--END OF CODE1
--CODE2
set song_file to "HFS:path:to:song_paths.txt"
set pp to read file song_file using delimiter return -- System's primary encoding, e.g., Mac-Roman
--set pp to read file song_file as «class utf8» using delimiter return -- UTF-8
repeat with p in pp
set p to p's contents
if (count p's words) > 0 then -- to skip quasi-blank line, just in case.
do shell script "afplay " & quoted form of p
end if
end repeat
--END OF CODE2
--CODE3
set song_file to "HFS:path:to:song_paths.txt"
try
set fref to open for access file song_file
set pp to read fref using delimiter return -- System's primary encoding, e.g., Mac-Roman
--set pp to read fref as «class utf8» using delimiter return -- UTF8
close access fref
on error errs number errn
try
close access file song_file
end try
error errs number errn
end try
repeat with p in pp
set p to p's contents
if (count p's words) > 0 then -- to skip quasi-blank line, just in case.
do shell script "afplay " & quoted form of p
end if
end repeat
--END OF CODE3
*If the text is encoded in UTF-8, read the file as such.
Statement to read the fie as UTF-8 is currently commented out.
*As shown in CODE3, if you open access for a file, you must make sure you close access for it. Failing to close access would result in subsequent error to read the same file in the same script session, i.e. in the same session of Script Editor or Applet execution. I'd suspect your error -39 would be caused by not closing access for the file in the previous run.
To close all access for files which are inadvertently left open, you may quit the current script session, i.e., current application, e.g., Script Editor.
Good luck,
H
Message was edited by: Hiroto