POSIX path conversion. Wy doesn't this work?

Given that thePaths is a list of files why doesn’t this work?


set theFiles to {} as string
			set n to 1
			repeat with counter from n to (count of thePaths)
				set placedPDF to item n of thePaths
				set PPDF to POSIX file placedPDF
				set item n of theFiles to PPDF
			end repeat

I get an applescript error saying:
“Can’t set item 1 of “” to file “blah/blah/blah.pdf”.”

but if I just do:
set placedPDF to item n of thePaths
set PPDF to POSIX file placedPDF
it set PPDF without an error…?

tia,
Aaron

Model: G5
AppleScript: xcode 2.1
Browser: Safari 412.2
Operating System: Mac OS X (10.4)

As advised elsewhere, there are a few issues involved here. The variable ‘n’ is set to 1, while ‘counter’ is the variable that will increment from 1 to (count of thePaths). This means that your loop will repeat the appropriate number of times but, since ‘n’ will always be 1, you’ll end up with a list containing repeats of only the first item in the list.

To convert all items in the list, try something like this:

set theFiles to {}
repeat with n from 1 to count thePaths
	set end of theFiles to POSIX file (item n of thePaths)
end repeat

An alternative syntax:

set theFiles to {}
repeat with currPath in thePaths
	set end of theFiles to POSIX file currPath
end repeat

If you have no further use for the original paths after conversion, you might even consider converting each item of the list in place, thus avoiding the need to build a new list altogether. (Here, let’s assume that the incoming list is already called ‘theFiles’, rather than ‘thePaths’):

repeat with n from 1 to count theFiles
	set item n of theFiles to POSIX file (item n of theFiles)
end repeat

kai,
Thanks so much for the reply, I really appreciate it. However, your last code
snippet doesn’t seem to work for me. If I do this:



set goFiles to (choose file with prompt "Select the PDFs." with multiple selections allowed)
log (count goFiles)

repeat with n from 1 to count goFiles
	set item n of goFiles to POSIX file (item n of goFiles)
end repeat


I get the following results:
get POSIX file (alias “05_raid4:PDF:004_A_09_05_StaffBox.pdf”)
“Can’t make POSIX file (alias "05_raid4:PDF:004_A_09_05_StaffBox.pdf") into type reference.”

I don’t know exactly what this means, and it’s kinda moot to me right now because I was completely off base in troubleshooting my indesign cs script, which I’ve finally figured out what the problem was. I’ve been trying to get indesign to place a pdf from a list and it doesn’t want to do that. I have to write the item to a variable and then use the place command on that single file.

Anyway, thanks I’m learning more and more and getting more and more confused too. :smiley:

:confused: Aa

“POSIX file” is expecting a POSIX-style (slash delimited) path (text) to turn into a file object. You’re giving it an alias object (which is Mac-style, aka colon delimited).

I’m not certain what you’re doing. perhaps you should try something like this:

choose file with prompt "Select the PDFs." with multiple selections allowed
set goFiles to result

repeat with n from 1 to (count goFiles)
	set item n of goFiles to POSIX path of (item n of goFiles)
end repeat