Re: file references
Re: file references
- Subject: Re: file references
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 15 Nov 2012 11:02:48 -0800
- Thread-topic: file references
Title: Re: file references
It's because you've been setting a reference outside any tell block to the Finder or System Events, so you're getting just the script's reference to a (MacOS) file, which has no properties, not to a Finder or System Events file that has a 'name' property.
You won't do much better if you substitute System Events for Finder in your script. You get the same error. That's because you are setting the reference to the file outside any application block, so what you're getting is a script reference, not a file reference. Your result for x should read:
file "Macintosh HD:Users:jimbrandt:•Partitions:HD2:Script Source:Libraries:DateLib.scpt" of «script»
But if you set the reference inside a Systems Events or Finder block, you get a result, not an error. Try this:
set filename to "Macintosh HD:Users:jimbrandt:•Partitions:HD2:Script Source:Libraries:DateLib.scpt"
tell application "System Events"
set x to a reference to file filename
set n to name of x
end tell
--> "DateLib.scpt"
And, in fact, this works in the Finder just as well:
set filename to "Macintosh HD:Users:jimbrandt:•Partitions:HD2:Script Source:Libraries:DateLib.scpt"
tell application "Finder"
set x to a reference to file filename
set n to name of x
end tell
--> "DateLib.scpt"
Both System Events and the Finder can quietly coerce either alias or file references to their own type of file, which have a 'name' property. But they have to be the "right kind" of file, as coerced within their own tell block. A reference to a 'file' outside a tell block won't work inside a tell block that has its own application definition of 'file'.
--
Paul Berkowitz
From: Jim Brandt <email@hidden>
Date: Thu, 15 Nov 2012 12:13:33 -0600
To: AppleScript-Users <email@hidden>
Subject: file references
What good is a file reference?
Example:
set filename to "Macintosh HD:Users:jimbrandt:•Partitions:HD2:Script Source:Libraries:DateLib.scpt"
set x to a reference to file filename
log x
tell application "Finder" to set n to name of x
results in a log showing:
(*file Macintosh HD:Users:jimbrandt:•Partitions:HD2:Script Source:Libraries:DateLib.scpt*)
tell application "AppleScript Editor"
get name of file "Macintosh HD:Users:jimbrandt:•Partitions:HD2:Script Source:Libraries:DateLib.scpt"
--> error number -1728 from file "Macintosh HD:Users:jimbrandt:•Partitions:HD2:Script Source:Libraries:DateLib.scpt"
The reason I'm asking this question is because the Finder returns a list of aliases whereas System Events returns a list of file references.
tell application "Finder" to set theList to (every item of folder sourceFolder)
vrs
tell application "System Events" to set theList to (every disk item of folder sourceFolder)
For a "large" directory (220 files and folders), several folders deep, the Finder took 25 seconds to return this list while System Events only took < 1 second.
If I then have to jump through hoops to use that reference though, I'll probably try a different way. (I'm leaning towards a Unix "ls" command).
TIA,
Jim Brandt
_______________________________________________
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
_______________________________________________
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