Re: file objects
Re: file objects
- Subject: Re: file objects
- From: Thomas Fischer <email@hidden>
- Date: Mon, 1 Mar 2010 11:23:35 +0100
Hello Axel,
thanks for the response.
So the result seems to be that AppleScript's "file objects" these days should be the «class furl» objects obtained through "choose file" or the POSIX file command (for these coercion to text also works as promised for these). Its appears odd though that such basic objects wouldn't even have a name in AppleScript (hence the "«…»").
The problem in my script is that some parts require POSIX paths (do shell script…) while others require "file objects" (standard AppleScript). To compare them I tried to coerce them to text and there the problems appeared.
set unixPath to POSIX path of myFile
works and yields "/Examples/03.pdf" whether myFile is a file object in the above sense(«class furl»: file "Macintosh HD:Examples:03.pdf"), a string in Mac format ("Macintosh HD:Examples:03.pdf") or a string in Unix format ("/Examples/03.pdf"). In particular, it is idempotent: the value doesn't change if you apply it to a POSIX path again.
To get the Mac file back is more complicated:
set macFile to POSIX file myFile
works only if myFile is actually a POSIX path, for a file as object or string it gives back something useless like ":Macintosh HD/Examples/03.pdf".
So to be on the save side to get a file object I should use:
set macFile to POSIX file (POSIX path of myFile)
Did I get that right?
Thomas
Am 28.02.2010 um 22:52 schrieb Axel Luttgens:
> In the ASLG for 2.0:
>
> You can use a file object to specify a name and location for a
> file that may not exist:
> set newFile to POSIX file "/Users/myUser/BrandNewFile.rtf"
> Similarly, you can let a user specify a new file with the choose
> file name (page 118) command, then use the returned file object
> to create the file.
>
> Strictly speaking, your negative result with
>
> set myFile to file "Macintosh HD:Examples:03.pdf"
>
> thus doesn't contradict the ASLG.
>
> Now, let's try this one:
>
> choose file name
> --> file "Some volume:some:path:to:some:file"
> class of result
> --> «class furl»
>
> So, both "POSIX file" and "choose file name" return objects displayed the same way in the log and belonging to the same class.
>
> Assuming file "Macintosh HD:Examples:03.pdf" exists, you may thus try:
>
> alias "Macintosh HD:Examples:03.pdf" as «class furl»
> --> file "Macintosh HD:Examples:03.pdf"
> class of result
> --> «class furl»
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden