I am puzzled.
When I run this short script from the script editor,
set _ to (path to desktop) as Unicode text
tell application "Finder" to display dialog "The item " & _ & " is
of class : " & class of item _
the result is
But, if I run the script as an application, it is:
Is it a normal behaviour?
This behaviour might seem a little perplexing, Yvan - but there's a
reason behind it.
When we compile/save a script, it's compiled as executable code,
rather than the form we see in a script editor. So, for example,
terms like 'creation date' and 'modification date' will be saved as
«class ascd» and «class asmo», respectively. To convert one form to
the other, the compiler compares the terms with those listed in
various AppleScript dictionaries (core terminology, scripting
additions and any relevant applications).
When we next open the script in a script editor, the compiler
reverses the process, by decompiling the raw code and displaying it
in human-readable form. To do this, it needs to refer once again to
the appropriate dictionaries. (That's why, when a script that
contains application-specific terms is opened, the app[s] concerned
may also be launched automatically.)
When a script is saved and run as an application, the raw code is
executed directly, without any decompiling. Normally, this is of no
concern to us. If we're trying to determine an object's properties,
we usually want only the value of those properties - not their
labels. (For example, our script may need to determine that an item
is of class folder or document file - which it can do quite happily
without coercing those classes to text.)
However, in cases where we want to use internal definitions in text
form, such as in a dialog, we need a way of forcing the compiler to
decompile raw codes like «class cfol» and «class docf» into their
more readily recognised terms: "folder" or "document file".
One way of doing this is to use the run script command to act upon a
text script (which will not yet have been compiled). When the terms
contained in the text are encountered, the compiler is called upon to
compile them as executable code - so that the script can be executed
in the normal way. For this, the relevant dictionaries need to be
accessed - after which the required terms become available to our
Such a statement can be added at the beginning of the script, and
needs no specific commands. Usually something like this should
suffice (to access Finder's terms):
run script "tell application \"Finder\"
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden