• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: file objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: file objects


  • Subject: Re: file objects
  • From: Axel Luttgens <email@hidden>
  • Date: Sun, 28 Feb 2010 22:52:12 +0100

Le 27 févr. 2010 à 18:41:58, Thomas Fischer a écrit :

> Hello,
>
> I ran into some problems with file objects and am wondering if I misunderstood something and/or how to treat them correctly (in the background is the problem of the three different ways AppleScript refers to elements of the file system).
>
> I can say
> 	set myFile to alias "Macintosh HD:Examples:03.pdf"
> but I get an error for
> 	set myFile to file "Macintosh HD:Examples:03.pdf"
>
> To get a file object, I seem to need an application.
>
> I can try the Finder:
>
> tell application "Finder" to set myFile to file "Macintosh HD:Examples:03.pdf"
> 		--> document file "03.pdf" of folder "Examples" of startup disk
> set myClass to class of myFile
> 		--> document file
>
> so this is a "document file", not a file.
>
> Or I can try System Events:
>
> tell application "System Events" to set myFile to file "Macintosh HD:Examples:03.pdf"
> 		--> file "Macintosh HD:Examples:03.pdf"
> set myClass to class of myFile
> 		--> file
>
> Or without an application I can use a POSIX path, trusting that "the result of evaluating a POSIX file specifier is a file object":
>
> set myFile to POSIX file "/Examples/03.pdf"
> 		-->file "Macintosh HD:Examples:03.pdf"
> set myClass to class of myFile
> 		-->«class furl»
>
> So this is not a file object.
>
> The AppleScript Language Guides claims "AppleScript supports coercion of a file object to a text", but funnily enough, from the above results the file object obtained from System Events is the only one that cannot be coerced to text but gives an error message.
>
> Can anybody illuminate the situation?

Hello Thomas,

The ASLG always has required some caution while reading those matters about files; moreover, things have evolved more or less silently.

In the ASLG for 1.3.7, one may read:

	You can obtain a file specification from the New File scripting
	addition command distributed with AppleScript, or from an
	application command that returns a file specification.
	[...]
	set fileSpec to new file default name "New Report"
	class of fileSpec --result: file specification

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»

HTH,
Axel


 _______________________________________________
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

References: 
 >file objects (From: Thomas Fischer <email@hidden>)

  • Prev by Date: Re: QuickTimePlayerX document properties
  • Next by Date: call soap to indesign server
  • Previous by thread: file objects
  • Next by thread: How do I change Object Color in Excel?
  • Index(es):
    • Date
    • Thread