Re: file references
Re: file references
- Subject: Re: file references
- From: "koenig.yvan" <email@hidden>
- Date: Thu, 15 Nov 2012 19:34:15 +0100
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).
In fact tell application "Finder" to set theList to (every item of folder sourceFolder) doesn't return a list of aliases but a list of references : {document file " maybe.scpt" of folder "® 2012-04-06 ƒ" of folder "Desktop" of folder "yvankoenig" of folder "Users" of startup disk of application "Finder", document file "01flat.pages" of folder "® 2012-04-06 ƒ" of folder "Desktop" of folder "yvankoenig" of folder "Users" of startup disk of application "Finder", document file "116_pages.pages" of folder "® 2012-04-06 ƒ" of folder "Desktop" of folder "yvankoenig" of folder "Users" of startup disk of application "Finder" If my memory i right, only the Finder may work using these references.
tell application "System Events" to set theList to (every disk item of folder sourceFolder) return a list of file references. {file "Macintosh HD:Users:yvankoenig:Desktop:® 2012-04-06 ƒ: maybe.scpt" of application "System Events", file "Macintosh HD:Users:yvankoenig:Desktop:® 2012-04-06 ƒ:.DS_Store" of application "System Events", file "Macintosh HD:Users:yvankoenig:Desktop:® 2012-04-06 ƒ:01flat.pages" of application "System Events",
Only System Events may use these file references.
This is why, most of the times, I use a third instruction :
tell application "System Events" to set theList to (path of every disk item of folder sourcefolder)
which returns the string version of aliases. {"Macintosh HD:Users:yvankoenig:Desktop:® 2012-04-06 ƒ: maybe.scpt", "Macintosh HD:Users:yvankoenig:Desktop:® 2012-04-06 ƒ:.DS_Store", "Macintosh HD:Users:yvankoenig:Desktop:® 2012-04-06 ƒ:01flat.pages",
I know that some users dislike these strings and prefer aliases.
If you really want aliases you must use :
tell application "Finder" to set theList to (every item of folder sourcefolder) as alias list which returns quickly a list of aliases. {alias "Macintosh HD:Users:yvankoenig:Desktop:® 2012-04-06 ƒ: maybe.scpt", alias "Macintosh HD:Users:yvankoenig:Desktop:® 2012-04-06 ƒ:01flat.pages", alias "Macintosh HD:Users:yvankoenig:Desktop:® 2012-04-06 ƒ:116_pages.pages:", On my machine, this instruction behave faster than your original one.
Yvan KOENIG (VALLAURIS, France) jeudi 15 novembre 2012 19:34:09
|
_______________________________________________
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