Thursday, December 18, 2014

#1 2007-12-31 10:01:04 pm

Kevin Bradley
Administrator
From: Independence, MO
Registered: 2006-03-13
Posts: 548
Website

Applescript 2.0 (Mac OS X 10.5 'Leopard ')

Application Objects

Lots of changes in the handling of application objects!  Some have been needed for a long time, others were unexpected, but useful.

New properties
Application objects now have a running boolean property that lets you test for a running application without resorting to System Events.  You can also test whether an application is frontmost using the frontmost property.  Lastly, you can get an application's version property without having to activate the application or send it any commands.

New behaviors
You can now target an application by its bundle identifier ("com.apple.mail" for example) or creator type ("emal").  This is useful for applications whose name may include a version number that changes from version to version.  The phrases application "Mail", application id "com.apple.mail" and application id "emal" are all valid references.  This means that there is new id property for applications, so if you use set appID to id of application "Mail" you will get "com.apple.mail" in appID.

If you refer to applications by id rather than name, the app will continue to be found by Applescript even if the user has changed its name.  But if you use this form and the application can't be found, Applescript won't ask the user to find it, it will throw an error (which you can catch with a try statement).

Other changes: Applications referenced in a tell block will launch hidden when commands are directed to them unless you specifically use launch or activate.  Applications are located "lazily" which means they aren't looked for until the script execution hits a tell block.  This also means that applications are re-found each time they are referenced in a tell block, so that if an application is moved it will be found each time it is referenced.  Apple's release notes also say:

This alleviates problems with scripts getting “stuck” to a particular copy of an application.

Apple notes that these new properties won't cause errors with most applications in older versions of Applescript - Applescript will send the events to an application rather than handling them, assuming that they are application events.  The release notes also say that most apps will handle name, version, and frontmost just fine in previous versions of Applescript, but that support for id or running would be rare.


Nitewing '98
--
I distrust morning people, largely because I suspect them of getting together early one day while the rest of us were asleep and setting up the rules of civilization.

Offline

 

#2 2008-01-01 12:27:03 am

Kevin Bradley
Administrator
From: Independence, MO
Registered: 2006-03-13
Posts: 548
Website

Re: Applescript 2.0 (Mac OS X 10.5 'Leopard ')

Scriptability Issues

Network preferences are now scriptable via System Events.  This means that you can use Applescript to change your network prefs, handy for laptops that connect to more than one network.  Apple provides the following example:

Applescript:


tell application "System Events"
   tell network preferences
       tell current location
           set aPPPoEService to a reference to (first service whose kind is 10)
           if exists aPPPoEService then
               connect aPPPoEService
           end if
       end tell
   end tell
end tell

In addition, both the Applescript Utility and Folder Action Setup are now scriptable, which means that administrators can write scripts to create folder actions and turn on Utility options.  Script Editor's scriptability has been enhanced as well, and all 3 applications are now VoiceOver aware.

Command Line Changes

The # character is now usable as a "comment to end of line" symbol, acting the same as the -- symbol.  This allows scripts to be executed like unix shell scripts, provided that the first line of the applescript is set to  #!/usr/bin/osascript and the file's execute permission is turned on.  Scripts that include the # character and are compiled under Applescript 2.0 will operate on older systems without problem. 

You can display compiled scripts on the command line with the osadecompile command.  The commands osascript and osacompile now handle UTF-8 encoded text scripts as well as UTF-16 and the primary encoding.  If a script is of neither UTF type it is assumed to be in the primary encoding.


Nitewing '98
--
I distrust morning people, largely because I suspect them of getting together early one day while the rest of us were asleep and setting up the rules of civilization.

Filed under: System

Offline

 

#3 2008-01-02 02:37:45 am

Kevin Bradley
Administrator
From: Independence, MO
Registered: 2006-03-13
Posts: 548
Website

Re: Applescript 2.0 (Mac OS X 10.5 'Leopard ')

Enhancements

Script Editor
You can now see all the inherited properties and elements of an object in the dictionary viewer.  You can turn this on in General preferences.

You can show the non-printing characters tab, carriage return, and linefeed in text constants as an escape sequence instead of a real tab, carriage return or linefeed, as it is now.  This preference is in the Editing prefs.

path to me will return the Script Editor if a script hasn't been saved yet.  Otherwise, it returns the path to the script's document file.

System Events
The properties server and zone have been added to disk objects for use with AppleShare.

File objects now have a default application property, similar to the info for's default application or the Finder's open with setting in Get Info.

System Events now has a downloads folder property.

System Events can control some Security preference settings with its new Security suite.

Two new properties have been added to the process class, bundle identifier and architecture, the latter specifying PowerPC or Intel (or some future architecture, it is assumed).

Property list items and files can be manipulated with the new Property List suite.

The name and id properties of an XML element object now reflect any name or id given in the XML code, and XML objects can be referenced using XML element id or XML element named syntax.

Image Events
RAW images are supported.

with pad color has been added to the pad command.

with compression level has been added to the save command for JPEG saving.


Nitewing '98
--
I distrust morning people, largely because I suspect them of getting together early one day while the rest of us were asleep and setting up the rules of civilization.

Offline

 

#4 2008-01-02 03:18:59 am

Kevin Bradley
Administrator
From: Independence, MO
Registered: 2006-03-13
Posts: 548
Website

Re: Applescript 2.0 (Mac OS X 10.5 'Leopard ')

Bug Fixes

Here are the highlights.  Here is a complete list of bugs that were fixed.

The delay command uses less CPU cycles.

Objects other than application and date specifiers will not be evaluated during compilation, but at run time.  This is especially important for alias and POSIX file items.

Script memory usage is no longer limited to 32mb.

Raw data literals are no longer limited to 127 bytes.

A script may not tell a remote application to do shell script.

Script Editor's handling of asian characters has been improved both when reporting errors or displaying applications in the Library window.

disk objects can tell the difference between disks with the same name.

file type and creator type work properly on Intel Macs.

The process class now reports false for the frontmost property if the front application is System Events or other UI element apps.  That means that first process whose frontmost is true will be the same application as path to frontmost application.

Folder Actions have been improved and Folder Actions Setup allows a script bundle as an action.

Database Events' performance is improved.


Nitewing '98
--
I distrust morning people, largely because I suspect them of getting together early one day while the rest of us were asleep and setting up the rules of civilization.

Offline

 

#5 2007-12-31 06:08:09 pm

Kevin Bradley
Administrator
From: Independence, MO
Registered: 2006-03-13
Posts: 548
Website

Re: Applescript 2.0 (Mac OS X 10.5 'Leopard ')

Applescript finally hits version 2.0!  AppleScript 2.0 was released as part of Mac OS X version 10.5 and requires Mac OS X version 10.5 or later.  The number of changes isn't perhaps as many as previous revisions, but they are major changes.  Let's take a look.

Apple provided the usual disclaimer in their release note.  It states that scripts written for older versions of AppleScript will work in 2.0 and that scripts written for 2.0 will work with versions back to version 1.1 if they don't use features added since that version.


Unicode Text

As we all thought might happen, all text in Leopard's Applescript is now unicode.  This means that the text, string, and unicode text classes are all functionally the same.  If you test the class of any of these items, you will get back the text class and they will all compare as equal.  However you will get unicode behavior whether you specify as unicode text or not, which may be different than the string behavior for some languages, especially for operations like words of.

This also means that the ascii number and ascii character commands are no longer valid.  In their place, text items now have an id property that returns the unicode value for a text character or a list of values for a string longer than 1 character.

Text characters that combine characters (like é or å) will return both the text value and the combined character, and Applescript 2.0 will count them as a single character when getting the length of a string.  Other changes required by the switch to unicode are (quoted from Apple's release notes):

Now that AppleScript preserves all characters correctly worldwide, it is also stricter about the text used in scripts. AppleScript syntax uses several non-ASCII characters, such as “≠” and “¬”. These characters must be typed exactly as the AppleScript Language Guide for AppleScript 1.3.7 describes. For compatibility with Asian national encodings, “《” and “》” are allowed as synonyms for “«” and “»”, since the latter do not exist in some Asian encodings.

Matching of text item delimiters now respects considering and ignoring attributes, where previous versions ignored them. The expansion attribute is no longer supported.

The change to all-Unicode necessitated a change in the read and write commands and how they deal with text encodings. Formerly, they would write string objects using the primary encoding and Unicode text objects as UTF-16, unless instructed otherwise using an as parameter. Now that there is only one text class, the read and write commands rely solely on the as parameter to determine the encoding: with no as parameter, as text, or as string, they use the primary encoding; with as Unicode text, they use UTF-16. For the most reliable results when creating scripts that will run on both 2.0 and pre-2.0, always specify the encoding explicitly using as text or as Unicode text, as appropriate. [4421553]

Because text item delimiters now respect considering and ignoring attributes, they now are case-insensitive by default. Formerly, they were always case-sensitive. To get the same behavior with 2.0 and pre-2.0, add an explicit considering case statement.

Because AppleScript 2.0 scripts store all text as Unicode, any text constants count as a use of the former Unicode text class, which will work with any version of AppleScript back to version 1.3. A script that contains Unicode-only characters such as Arabic or Thai will run, but will not be correctly editable using pre-2.0 AppleScript: the Unicode-only characters will be lost.


Nitewing '98
--
I distrust morning people, largely because I suspect them of getting together early one day while the rest of us were asleep and setting up the rules of civilization.

Offline

 

#6 2008-01-02 03:55:58 am

Kevin Bradley
Administrator
From: Independence, MO
Registered: 2006-03-13
Posts: 548
Website

Re: Applescript 2.0 (Mac OS X 10.5 'Leopard ')

Developer Notes

The full developer notes are available here.  Of note are that sdef's can be read directly instead of launching the application to read them, and that there is a new sdef architecture.


Nitewing '98
--
I distrust morning people, largely because I suspect them of getting together early one day while the rest of us were asleep and setting up the rules of civilization.

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.054 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)