Re: POSIX and lists question
Re: POSIX and lists question
- Subject: Re: POSIX and lists question
- From: kai <email@hidden>
- Date: Thu, 11 Aug 2005 03:47:04 +0100
On 11 Aug 2005, at 01:47, aaron spesard wrote:
Why doesn't this work?
set theFiles to {}
set n to 1
repeat with counter from n to (count of thePaths)
-- thePaths is a bunch of PDFs dropped on the window.
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"."
Once you've sorted out the list stuff as Andrew advises, Aaron, you
could still have an issue with the repeat loop.
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 using Andrew's suggestion
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden