Re: Finder scripting dies
Re: Finder scripting dies
- Subject: Re: Finder scripting dies
- From: Christopher Nebel <email@hidden>
- Date: Tue, 21 Oct 2003 19:47:22 -0700
On Oct 21, 2003, at 7:01 PM, Deivy Petrescu wrote:
Why does this works:
set k to (path to the desktop) as string
tell application "Finder" to get name of folder (k)
-->Desktop
and this:
set k to (path to the desktop) as string
tell application "Finder" to get name of alias (k)
-->Desktop
but this doesn't:
set k to (path to the desktop) as string
tell application "Finder" to get name of folder ( alias k)
-->"Finder got an error: A descriptor type mismatch occurred."
However, this does:
tell application "Finder" to get name of folder (alias
"SantosFC:Users:deivy:Desktop:")
-->Desktop
There's some fairly serious squirreliness in how AppleScript handles
this sort of thing. First, the ground rules:
1. The Finder understands two kinds of selection data for files and
folders (that are relevant here): string names, and alias records (that
is, typeAlias, which is *not* the same thing as an alias object
specifier -- they're hard to tell apart, because they look the same in
the event log).
2. The Finder, if asked to evaluate "alias blah", will return a
Finder-style long specifier (file "foo" of folder "bar" of ...). It
can also get properties of an alias specifier as if it were an "item"
specifier.
3. AppleScript will take constant alias expressions (i.e., 'alias
"some:path"') and turn them into alias records at compile time.
Combining these three rules gives the behavior you're seeing.
- The first case works because of #1.
- The second case works because of #2.
Now things get interesting...
- The third case evaluates "alias k" first, and because it tells the
Finder to do that, the result is 'folder "Desktop" of folder "deivy" of
...', so the next step is to get 'folder (folder "Desktop" of folder
"deivy" of ...)', which fails because of #1.
- The fourth case works, because the expression 'alias
"SantosFC:Users..."' turns into an alias record at compile time, so the
Finder gets asked for 'folder (typeAlias data)', which works because of
#1. This is effectively the same thing as 'set k to path to desktop;
tell app "Finder" to get name of folder k'.
--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.