Re: Coerce file reference to text
Re: Coerce file reference to text
- Subject: Re: Coerce file reference to text
- From: kai <email@hidden>
- Date: Fri, 12 May 2006 01:25:18 +0100
On 11 May 2006, at 08:13, Emmanuel wrote:
At 3:05 PM -0400 5/10/06, Sam wrote:
set filelist to POSIX path of every file of folder UserResponse
whose file type contains "XPR"
I don't think Finder nor System Events can handle that kind of
reference: "POSIX path of every file blah". I would try not to
apply "POSX path" to a set of files. Rather, I would apply it to
each file in a loop.
I believe that's the case with Finder, Emmanuel - since there's no
POSIX path property there. In System Events, however, the file class
inherits from disk item - which has a POSIX path property. So System
Events should really be capable of getting multiple POSIX paths.
There's also a syntactic issue to watch out for here - in that System
Events evidently can't coerce an alias to a reference. In this
context, the fact that Finder can (and does) might just add to the
confusion.
--------
set f to choose folder
tell application "Finder" to folder f
--> folder "x" of folder "y" of startup disk of application "Finder"
--------
set f to choose folder
tell application "System Events" to folder f
--> error number -1700 [errAECoercionFail]:
(* System Events got an error: Can't make folder (alias
"path:to:folder:") into type reference. *)
--------
Either a straight reference or an alias (but not both) should work:
--------
set UserResponse to (choose folder) as Unicode text
tell application "System Events" to set filelist to POSIX path of ¬
every file of folder UserResponse whose file type contains "XPR"
--> list of POSIX paths
--------
set UserResponse to choose folder
tell application "System Events" to set filelist to POSIX path of ¬
every file of UserResponse whose file type contains "XPR"
--> list of POSIX paths
--------
On 10 May 2006, at 20:05, Sam wrote:
I thought I would be smart and use offset to find the /Volumes/ and
strip it out but I'm coming up with air biscuits.
The following reflects the POSIX path but offset fails to get any
number other than zero.
So it appears that this is not a string after all. And I don't
think it's made up of words that are readily delimited.
But I'm also unable to get a few characters. Is it just one long
string of characters? Or is it something I can work with?
Since I don't think this point was explained, Sam, perhaps I can
cover it briefly now. The problem is actually more to do with the
construct of the repeat loop:
repeat with i from 1 to number of items in filelist
get offset of "s/" in i
end repeat
With this form of repeat, the variable i is an incrementing integer
(1, 2, 3, etc.) - and, since those values don't contain the string
"s/", a zero is returned in each case. You'd really need something
more like:
offset of "s/" in filelist's item i
(However, the suggestion I posted earlier would exclude the string "/
Volumes/" anyway.)
---
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