• 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: Dialog from script application displays raw codes (was: no subject)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dialog from script application displays raw codes (was: no subject)


  • Subject: Re: Dialog from script application displays raw codes (was: no subject)
  • From: kai <email@hidden>
  • Date: Sun, 27 Aug 2006 13:19:20 +0100


On 27 Aug 2006, at 09:20, Yvan KOENIG wrote:

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

folder

But, if I run the script as an application, it is:

«class cfol»

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 main script.

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\"
end"
----------

---
kai


_______________________________________________ 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
  • Follow-Ups:
    • Re: Dialog from script application displays raw codes (was: no subject)
      • From: Yvan KOENIG <email@hidden>
References: 
 >(no subject) (From: Yvan KOENIG <email@hidden>)

  • Prev by Date: (no subject)
  • Next by Date: Re: Dialog from script application displays raw codes (was: no subject)
  • Previous by thread: (no subject)
  • Next by thread: Re: Dialog from script application displays raw codes (was: no subject)
  • Index(es):
    • Date
    • Thread