Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: What is "Using Terms From..."
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is "Using Terms From..."



> I'm learning how to do some basic scripts to apply to mail.app.
>
> However, the first script from apple that I opened (with the intention
> of learning something) I found began with the following line:
>> using terms from application "Mail"
>
> I have not come across this before and I can't find a reference to it.
>
> Where can I find reference information on why this is used and how it is
> used.

I think there is no official explanation (though you can find thousands of
references in the www). It was first born with AS 1.4 (that's why you can't
find in the AppleScript Language Guide, for 1.3.7).

Using this clause, you instruct the compiler to use the related thing's
terminology for the nesteed statements, only to compile such statements (so
you don't need the related thing at run-time). The classic example is using
this feature to compile certain code in your machine, which will run in
others' machines, even if their target apps have a different name.

For example, you make a very simple script which will grab the title of the
current window in FileMaker:

#################################################################
tell application "Finder" to set FM to name of ¬
    (get application file of ¬
        (get first process whose creator type starts with "FMP"))

using terms from application "FileMaker Developer"
    tell application FM
        try
            set wname to name of window 1
        on error --> support FMP5-6
            try
                set wname to name of database 1
            on error
                display dialog "Unsupported FM version!!!"
            end try
        end try
    end tell
end using terms from
#################################################################

You have a copy of FM Developer, and you use it to compile the code
(keywords as "database"). Otherwise, removing the "using terms" clause, you
couldn't compile the code, as the compiler doesn't know what is the value of
the variable "FM" till the code is run.

This way, you use your local copy of FM Developer to compile the code but,
at run time, it will be invoked the application "FM" (which could be FMP7,
FMP8, FMP5, etc.).

This is used specially when your target is the same application with
different names/versions (eg, PhotoShop CS and PhotoShop CS2), only if the
same code works fine for the various versions.

And the introduction of this clause in AS replaced the old "double tell"
technique.


There are more uses for this clause. For example, read this one:

<http://bbs.applescript.net/viewtopic.php?pid=46780>

Finally, AS 1.7 introduced a new use in "using terms from" clauses for
remote procedure calls (SOAP, etc.) --> regular uses are very similar to the
"unknown target" described above. See an example here:

<http://developer.apple.com/documentation//AppleScript/Conceptual/soapXMLRPC
/chapter3/chapter_3_section_3.html>


Finishing...

I'll try to guess why you saw your "using terms from".

Some applications are "attachable": you can run scripts from within such
app, or such app can make use of scripts to modify its behaviour. These apps
are, for example, those ones with a script menu: Mail? (not sure, I don't
use it), iTunes, Entourage, Tex-Edit Plus, Smile, etc.

In these scripts, the default target is usually the application itself.
Though not explicit, these scripts are equivalent:

Eg, when run from Smile:
#################################################################
display dialog (get name of window 1)
#################################################################

#################################################################
tell application "Smile"
    display dialog (get name of window 1)
end tell
#################################################################

Now, let's imagine you're writing a script for "iTunes". You can't simply
compile the keyword "play", so you must target iTunes using one of "using
terms from blah" or "tell application blah".

But some times you can't "tell application blah". This is when the related
application defines handlers (such as "on opening folder theFolder" for
Folder Actions, or "on perform mail action with messages msgs" in Mail). The
only way to compile such thing is making use of "using terms from blah" (not
needed for handlers defined in scripting additions, but mandatory for
application's ones):

#################################################################
using terms from application "Mail"
    on perform mail action with messages msgs for rule x
        repeat with i from 1 to count msgs
            make new outgoing message at beginning with properties ¬
                {subject:"RE: " & (get subject of msgs's item i),
visible:true}
        end repeat
    end perform mail action with messages
end using terms from
#################################################################


jj

--
http://www.macscripter.net/
http://www.osaxen.com/


 _______________________________________________
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

References: 
 >What is "Using Terms From..." (From: Richard Bullen <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.