TweetFollow Us on Twitter

What's New With AppleScript In Tiger

Volume Number: 21 (2005)
Issue Number: 5
Column Tag: Programming

AppleScript Essentials

What's New With AppleScript In Tiger

by Benjamin S. Waldie

Lately, there has been a lot of buzz about Tiger, the latest version of Mac OS X. This new operating system version is full of new features and other goodies. With new applications and utilities like Dashboard, Spotlight, and Automator, Tiger is breathing still more new life into the steadily maturing Mac OS X.

While many of the new features in Tiger are geared toward the user level, there is also plenty that is new under the hood for developers. For AppleScripters, Tiger brings with it a number of bug fixes and new features with the latest release of AppleScript, version 1.10. In this month's article, we will walk through a number of these changes and enhancements.

AppleScript Bug Fixes

Like most operating system updates, Tiger offers AppleScript developers a number of bug fixes. Let's touch briefly on a few of these, and then we will move on to the exciting stuff, the new AppleScript-related features in the OS. In addition to a number of others, the following bug fixes have been introduced in Tiger:

  • Memory leaks in both AppleScript itself, as well as in the Standard Additions scripting addition have been fixed
  • AppleScript has been updated to allow for compiling larger scripts, as well as generating larger static lists.
  • In Mac OS X 10.3, retrieving the POSIX path of a string that is already in the POSIX file format would produce the incorrect result. This has now been fixed. For example:

Under Mac OS X 10.3, Panther:

POSIX path of "/Users/bwaldie/Desktop/"
--> "/:Users:bwaldie:Desktop:"

Under Mac OS X 10.4, Tiger:

POSIX path of "/Users/bwaldie/Desktop/"
--> "/Users/bwaldie/Desktop/"

A slew of other bug fixes have also been introduced with Tiger. For a comprehensive list of bug fixes, view the AppleScript Release Notes, available in the Apple Developer Connection Library. Also, if you encounter a bug with AppleScript, or any other Apple technology for that matter, be sure to submit it via the bug reporter website at http://bugreport.apple.com. You will need to have at least an online ADC membership to log into this website.

New AppleScript Features

While bug fixes are exciting in their own special way, the real fun comes with all of the new AppleScript features and additions in Tiger. Throughout the remainder of this month's article, we will discuss a handful of these new features. Let's start with Script Editor.

Script Editor Enhancements

With the release of Mac OS X 10.3, Apple introduced a new and improved Script Editor, version 2.0, a long awaited and much needed upgrade from its predecessor. With Tiger, Apple continues to expand the functionality in Script Editor with the release of version 2.1.

In the latest version of Script Editor, you will find an enhanced version of the Script Assistant, which helps to auto-complete your code as you type. Enabling this feature in Script Editor's preferences now no longer requires that you re-launch Script Editor to begin using the feature. In addition, the latest rendition of this feature is now able to auto-complete variables and handler names.


Figure 1. Handler Call Auto-Completion Using the Script Assistant

You may recall that Mac OS X 10.3 introduced the ability to save AppleScript files in bundle format. By saving a script as a bundle, required resources could be embedded directly into the script's bundle via the Finder, eliminating the need for the script to locate and access external required components. Script Editor 2.1 takes script bundles a step further, by allowing you to actually edit the contents of a bundle from directly within Script Editor.

When editing a script that has been saved as a bundle, click the Bundle Contents button in the script window's toolbar. The contents of the bundle will be displayed in a drawer attached to the window. New components can be added to the script bundle by simply dragging and dropping them directly into the bundle contents drawer. Bundle components may also be deleted, renamed, opened, and duplicated from within the drawer.


Figure 2. Bundle Contents Drawer

Possibly the most exciting and visible feature of the latest version of Script Editor is a new AppleScript dictionary browser layout. This new layout offers a completely redesigned way to navigate AppleScript dictionaries.


Figure 3. New Script Editor Dictionary Browser

Viewing an AppleScript dictionary in this new browser display may seem a little confusing at first glance. However, you will quickly find that the new format is actually quite easy to use, and contains a number of benefits over previous dictionary browsers. Before long, you will wonder how you ever worked without it.

At the top of the dictionary browser, you will find a toolbar, complete with navigation buttons and a search field for performing quick terminology searches. If desired, the toolbar may be custom configured, or hidden entirely.

With adjustable navigation panes, the dictionary browser window itself may be configured for navigation using columns, or in the familiar list view format of previous script editors. By collapsing and expanding the panes of the browser, you can design the layout to a look and feel that is comfortable for you. Once you have finished customizing the layout of the dictionary browser to your liking, select Save as Default from the Window menu, and all future dictionary browsers will open using your custom configuration.

While navigating a dictionary in column view, the dictionary's terminology will be displayed in suites by default. Selecting a suite will display a list of commands and classes within that suite. Optionally, you may choose to view a dictionary by its class containment or inheritance, allowing you to gain an understanding of the class hierarchy within the dictionary. This can be done by clicking the desired view button in the toolbar.


Figure 4. Viewing a Dictionary by Containment

As you explore the new dictionary browser, you will notice that each term in the navigation panes is preceded by a color-coded, labeled icon. These icons indicate the type of term. For example:

  • An orange square containing the letter S indicates a suite
  • A blue circle containing the letter C indicates a command
  • A purple square containing the letter C indicates a class
  • A purple square containing the letter P indicates a property
  • An orange square containing the letter E indicates an element

Another very exciting feature of Script Editor's new dictionary browser is that hyperlinks now provide quick and easy one-click navigation between related terms. For example, you can select a class in a dictionary, and click on one of its elements to go directly to that element.

In Tiger, developers can now even choose to enhance their product's AppleScript dictionaries by including comprehensive HTML-based documentation, which can even include example scripts and URL's, all contained and viewable within the dictionary itself! Hopefully, developers will be quick to adopt this new functionality. One application that is already taking advantage of this new capability is PreFab Software's UI Actions. The AppleScript dictionary for the latest release of UI Actions includes extensive documentation, along with sample code to get scripters up and running in no time.


Figure 5. PreFab UI Actions Dictionary with HTML Documentation

PreFab UI Actions provides AppleScript developers with a way to universally attach scripts to almost any application. UI Actions can be configured to trigger scripts when users click buttons in an application's interface, select menu items, open a window, and much more. Find out more about Prefab UI Actions, or download a 30-day trial version at http://www.prefab.com/uiactions/.

AppleScript Utility

Outside of Script Editor, Tiger also includes a number of other new AppleScript-related features. One such feature is a new AppleScript Utility application, which provides a central location for performing a number of system-wide AppleScript-related tasks, such as changing your default script editor, enabling GUI scripting or the Script Menu, or working with Folder Actions. This utility can be found in the Applications > AppleScript folder.


Figure 6. AppleScript Utility Application

New Standard Addition Commands

Tiger also brings with it some new and enhanced AppleScript terminology. Some of this new terminology can be found in the Standard Additions scripting addition.

In the User Interaction suite of the Standard Additions scripting addition, a command for displaying a new type of interface dialog has been added. A new display alert command will allow a system alert message to be displayed to the user. This command has a number of configurable parameters, including the text to be displayed, the level of the alert, and the names of the buttons. The following is an example of code that will display a basic alert dialog:

display alert "An error has occurred." message "Document could not be found." as warning


Figure 7. Display Alert Dialog

The display dialog command in the Standard Additions scripting addition has always been a popular way of displaying a basic message, or requesting text input from the user during the execution of a script, without the need to design a full-blown AppleScript Studio application. However, one thing that the display dialog command has lacked is the ability to hide text entered by the user... until now. Tiger features an updated display dialog command, which now includes a hidden answer parameter, allowing text entered by the user to be displayed as bullets. For example:

display dialog "Please enter your secret access key:" default answer "" with hidden answer


Figure 8. Display Dialog with a Hidden Answer

While other new commands and terminology are available in Tiger, the last one that I want to mention in this article is the new system info command. This command, which can be found in the Miscellaneous Commands suite in the Standard Additions scripting addition, will retrieve a variety of information about the current system configuration, including the system version, current user name, IP address, and more. For example:

system info
--> {AppleScript version:"1.10", AppleScript Studio version:"1.4", 
system version:"10.4", short user name:"bwaldie", long user name:"Ben Waldie", 
user ID:501, user locale:"en_US", home directory:alias "Macintosh HD:Users:bwaldie:", 
boot volume:"Macintosh HD", computer name:"Ben Waldie's iMac G5", host 
name:"ben-waldies-imac-g5.local", IPv4 address:"192.168.2.5", primary Ethernet 
address:"00:11:24:70:db:be", CPU type:"PowerPC 970", 
CPU speed:1599, physical memory:768}

System Events

You may already be familiar with the System Events application in Mac OS X. This application provides a central location for performing system-related tasks with AppleScript. In the past, System Events has been primarily used by developers to interact with non-scriptable application interfaces via a Processes Suite, also known as GUI scripting. In Tiger, System Events' AppleScript dictionary has been expanded with some new suites of classes and commands, which are sure to become quite popular as well.

A new QuickTime File Suite, Movie File Suite, and Audio File Suite offer developers a way to access basic information about digital media files, without the need to open those media files in an associated application, such as QuickTime or iTunes. For example, the following code will retrieve information about a specified movie file.

set theMovie to (choose file of type "MooV") as string
tell application "System Events"
   properties of contents of movie file theMovie
end tell

--> {modification time:date "Wednesday, January 31, 2001 12:30:38 AM", stored 
stream:false, auto present:false, time scale:600, preferred volume:255, class:movie 
data, auto quit when done:false, bounds:{0, 0, 240, 180}, resizable:stop, 
looping:false, natural dimensions:{0, 0, 240, 180}, presentation mode:stop, 
data size:5816280, href:"file://localhost/Users/bwaldie/Desktop/starwars.mov", 
creation time:date "Wednesday, January 31, 2001 12:30:34 AM", preferred rate:65536, 
auto play:false, duration:26152, preview duration:0, preview time:0}

A new XML Suite in System Events provides a way to extract data from an XML file, without the need to write complex parsing code, or resort to using a scripting addition. In addition, a new Property List Suite can be used to quickly and easily extract and set property item values in property list files. For example, the following code will determine whether tabbed browsing is enabled in Safari, by extracting the value of the appropriate property in Safari's property list file.

set thePropertyListFile to (path to preferences as string) & "com.apple.Safari.plist"
tell application "System Events"
   value of property list item "TabbedBrowsing" of contents of property list file 
      thePropertyListFile
end tell

--> true

Database Events

One feature that is sure to generate a lot of excitement in the AppleScript community is the new Database Events background application. This application, which is located in System > Library > CoreServices, can be used to programmatically generate SQL databases. This capability opens up a whole new world of possibilities for AppleScripters who need a place to store data when running a script. Rather than storing data in a property, or writing it to a text file, it can now be added to an SQL database, directly from AppleScript.

For example, the following code will create a new SQL database in memory, and add two records with fields containing user data. The script will then locate the record whose last name field matches my last name, "Waldie".

tell application "Database Events"
   set myDatabase to make new database with properties {name:"My Database"}
   tell myDatabase
      set myFirstRecord to make new record with properties {name:"User Entry"}
      tell myFirstRecord
         make new field with properties {name:"FirstName", value:"Ben"}
         make new field with properties {name:"LastName", value:"Waldie"}
      end tell
      set mySecondRecord to make new record with properties {name:"User Entry"}
      tell mySecondRecord
         make new field with properties {name:"FirstName", value:"John"}
         make new field with properties {name:"LastName", value:"Smith"}
      end tell
      return every record whose value of field "LastName" = "Waldie"
   end tell
end tell

--> {record id 137689274 of database "My Database" of application "Database Events"}

A database that is created or loaded in memory using Database Events will remain opened until it you close it using the close command, or until the Database Events application quits. When idle, Database Events will automatically quit after 5 minutes of inactivity. However, this amount of time may be extended or reduced by modifying the quit delay property of the Database Events application. For example, the following code sets Database Events to idle for 600 seconds, or 10 minutes, before quitting.

tell application "Database Events"
   set quit delay to 600
end tell

You may also choose to save a database using the save command in Database Events. By default, databases are saved into a Documents > Databases folder within your user folder. However, you may specify a different path, if desired, by specifying a folder path in the location property of a database. For example, the following code will create a database, and then save it to the desktop:

tell application "Database Events"
   set myDatabase to make new database with properties {name:"My Database", 
      location:path to desktop}
   save myDatabase
end tell

Database Events is shaping up to be a very useful tool for AppleScript developers. Personally, I have only just started using it, but I can already see new possibilities for how I store and access data from within my scripts.

AppleScript Studio

In addition to changes made to AppleScript in general in Tiger, AppleScript Studio has also undergone some changes as well. For developers creating projects in AppleScript Studio, you will find improvements to data views and drag and drop, support for compiled scripts in Xcode projects, an enhanced code assistant, an updated dictionary browser, and more.

Probably the most significant enhancement to AppleScript Studio, though, is the ability to create Automator actions. When creating a new project in Xcode, a new template exists for an AppleScript-based Automator action. Using this template, developers can quickly build customized Automator actions, primarily using AppleScript.

Next month's article will provide an introduction to AppleScript Studio, for those that have not yet gotten their feet wet. The following month, we will discuss the steps involved in building a custom AppleScript-based Automator action, using AppleScript Studio.

In Closing

As you can see, the AppleScript team at Apple has continued to add great new features and enhancements to AppleScript with yet another release of Mac OS X. The topics covered in this article really only scratch the surface of these changes. For a comprehensive list of enhancements and bug fixes, be sure to check out the AppleScript release notes and the AppleScript Studio release notes. These documents can be found in the Apple Developer Connection Library at http://developer.apple.com/releasenotes/applescript/.

Also, some features, like Database Events and System Events changes, have not been listed in the release notes. So, be sure to explore Tiger on your own, and begin learning about this, and other exciting new AppleScript capabilities.

Until next time, keep scripting!


Benjamin Waldie, author of the best selling books "AppleScripting the Finder" and the "Mac OS X Technology Guide to Automator", available from www.spiderworks.com, is president of Automated Workflows, LLC, a firm specializing in AppleScript and workflow automation consulting. For years, Benjamin has developed professional AppleScript-based solutions for businesses including Adobe Systems, Apple Computer, NASA, PC World, and TV Guide. In addition to his role as a consultant, Benjamin is an evangelist of AppleScript, and can frequently be seen presenting at Macintosh User Groups, Macworld, and other events. For additional information about Benjamin, please visit www.automatedworkflows.com, or email Benjamin at applescriptguru@mac.com.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Opera 81.0.4196.60 - High-performance We...
Opera is a fast and secure browser trusted by millions of users. With the intuitive interface, Speed Dial and visual bookmarks for organizing favorite sites, news feature with fresh, relevant content... Read more
Fantastical 3.5.1 - Create calendar even...
Fantastical is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event... Read more
Evernote 10.26.5 - Create searchable not...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
Parallels Desktop 17.1.1 - Run Windows a...
Parallels allows you to run Windows and Mac applications side by side. Choose your view to make Windows invisible while still using its applications, or keep the familiar Windows background and... Read more
BBEdit 14.0.3 - Powerful text and HTML e...
BBEdit is the leading professional HTML and text editor for the Mac. Specifically crafted in response to the needs of Web authors and software developers, this award-winning product provides a... Read more
Minecraft 973 - Popular sandbox building...
Minecraft allows players to build constructions out of textured cubes in a 3D procedurally generated world. Other activities in the game include exploration, gathering resources, crafting, and combat... Read more
Viber 16.6.0 - Send messages and make fr...
Viber lets you send free messages and make free calls to other Viber users, on any device and network, in any country! Viber syncs your contacts, messages and call history with your mobile device, so... Read more
iMazing 2.14.6 - Complete iOS device man...
iMazing is the world’s favourite iOS device manager for Mac and PC. Millions of users every year leverage its powerful capabilities to make the most of their personal or business iPhone and iPad.... Read more
Vivaldi 5.0.2497.24 - An advanced browse...
Vivaldi is a browser for our friends. We live in our browsers. Choose one that has the features you need, a style that fits and values you can stand by. From the look and feel, to how you interact... Read more
Vitamin-R 4.05 - Personal productivity t...
Vitamin-R creates the optimal conditions for your brain to work at its best by structuring your work into short bursts of distraction-free, highly focused activity alternating with opportunities for... Read more

Latest Forum Discussions

See All

TouchArcade Game of the Week: ‘Rocket Le...
After years and years and years of people demanding an official Rocket League game on mobile, developer Psyonix has finally delivered with their made-for-mobile spin-off Rocket League Sideswipe. Now, an ultra-popular IP releasing a mobile-ized... | Read more »
Steal Your Enemy’s Powers in ‘Mimelet’,...
Developer Neutronized is probably most well-known for the excellent Super Cat Tales series, but they are seemingly always putting out other unique and colorful titles too. It’s especially impressive considering this is just a solo developer. As work... | Read more »
SwitchArcade Round-Up: ‘Big Brain Academ...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for December 3rd, 2021. In today’s article, we’ve got a bit of news about an upcoming addition to the Nintendo Switch Online Expansion Pass before we head into today’s new releases.... | Read more »
Rocket League Sideswipe: Season 1 and Cr...
Rocket League Sideswipe’s pre-season has ended and all ranks have been reset. But here’s the great news – season 1 is officially on and a new event has arrived! Turbo Season has already kicked off and will last until January 25th. [Read more] | Read more »
‘Dandara: Trials of Fear+’ and Our 2018...
This week, two App Store Greats join Apple Arcade alongside big updates to some excellent games on the service. With no new game announced yet, it looks like Disney Melee Mania might be the final new game of 2021 for the service barring any last... | Read more »
Mini Metro’s New Big Update Adds the Add...
\ Dinosaur Polo Club has made sure 2021 is awesome for Mini Metro ($3.99) players through big updates. We’ve had the Chongqing map, Budapest, and more arrive for free on iOS and Android. Mini Metro was also added to Apple Arcade as Mini Metro+ this... | Read more »
SwitchArcade Round-Up: ‘Archvale’, ‘Aste...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for December 2nd, 2021. My time was tight today, friends. I spent four hours or so in the hospital getting my ticker thoroughly checked after a bit of a scare yesterday. Luckily, all... | Read more »
‘Final Gear’ is Adding Iconic Evangelion...
Final Gear, Komoe Technology Limited’s mech and maiden-themed mobile RPG, has just announced an exciting crossover event with the similarly mech-themed IP, Evangelion. The collab with the popular franchise lets players pilot iconic Evangelion mechs... | Read more »
Lineage2M is the beautiful MMORPG from N...
Good news for Lineage2 fans everywhere - Lineage2M, NCSOFT's new mobile title that boasts high-quality 3D in 4K resolution, is out now on PC, Android, and iOS devices across the globe. Players can now dive into a vast open-world environment and... | Read more »
‘Lineage2M’ is NCSOFT’s Gorgeous MMORPG...
Servers are now live for Lineage2M, NCSOFT’s gorgeous-looking MMORPG that follows up on the success and quality of the Lineage2 franchise. Out now on iOS, Android, and on PC, the new mobile title features consistent high-end graphics, massive... | Read more »

Price Scanner via MacPrices.net

Holiday Sale! Apple AirPods for only $79, $50...
AT&T has base-model Apple AirPods with Charging Case, 2nd generation, on Holiday sale for only $79 while supplies last. Their price is $50 off Apple’s MSRP, and it’s the lowest price we’ve ever... Read more
New Holiday sale at AT&T: $200 off any Ap...
AT&T is offering Apple Watch models for $200 off MSRP when you purchase two Watches with AT&T service and add at least one new line. The fine print: “Enjoy $200 off Apple Watch when you buy... Read more
Save $260 on 13″ M1 16GB RAM/512GB SSD MacBoo...
Apple has 13″ M1 MacBook Pros with 8GB of RAM and 256GB or 512GB SSDs for $200-$230 off MSRP, Certified Refurbished. If 8GB of RAM is not enough for you, Apple has restocked custom-configurations... Read more
AirPods Max headphones back on Holiday sale f...
Amazon has Blue and Space Gray AirPods Max headphones on sale again for $120 off Apple’s MSRP, down to $429. Shipping is free. Their price is the lowest we’ve ever seen for AirPods Max headphones... Read more
Back in stock! $589 M1 Mac minis at Apple, Ce...
Apple has restocked the base M1-powered Mac mini in their Certified Refurbished section for only $589. Each mini comes with Apple’s one-year warranty, and shipping is free: – M1 Mac mini (8GB RAM/... Read more
Apple has restocked 2nd generation 4K Apple T...
Apple has restocked a full line of Certified Refurbished 2nd generation 32GB and 64GB 4K Apple TVs with Siri remotes for $30 off the cost of new models. Apple’s standard one-year warranty is included... Read more
In stock today: 13″ Gray M1 MacBook Pros for...
Apple’s 13″ Space Gray MacBook Pros with M1 Apple Silicon CPUs are on sale at B&H Photo today for $100-$150 off MSRP, starting at $1199. Free 1-2 shipping is available for most addresses in the... Read more
Looking for an iPad Pro? Get last year’s mode...
Apple has Certified Refurbished 2020 11″ and 12″ iPad Pros available in their online store in a variety of configurations. Models start at $609 and range up to $350 off Apple’s original MSRP. Each... Read more
Clearance 2020 Intel-based 16″ MacBook Pros i...
Apple has Certified Refurbished 2020 16″ 2.6GHz 6-Core MacBook Pros in stock for $1949 including free shipping. Their price is $450 off original MSRP. Each model features a new outer case, is in like... Read more
13″ M1 MacBook Pro with 512GB SSD on Cyber Mo...
Amazon has the Space Gray 13″ M1 MacBook Pro with a 512GB SSD on Cyber Monday 2021 sale for $250 off MSRP shipped: – 2020 13″ MacBook Pro Space Gray M1 CPU/512GB SSD: $1249.99 $250 off MSRP Their $... Read more

Jobs Board

Geek Squad Advanced Repair *Apple* Professi...
**843364BR** **Job Title:** Geek Squad Advanced Repair Apple Professional **Job Category:** Store Associates **Store Number or Department:** 000853-Jackson-Store Read more
*Apple* End User Support Specialist - North...
…of Key Responsibility: 1. Responsible for support of all College owned Apple computers, mobile ios devices and peripherals such as monitors, keyboards, printers, Read more
Geek Squad Advanced Repair *Apple* Professi...
**843218BR** **Job Title:** Geek Squad Advanced Repair Apple Professional **Job Category:** Store Associates **Store Number or Department:** 001763-Lady Lake-Store Read more
Sr. Technical Support Specialist ( *Apple* /M...
Description Technical Support, Sr. ( Apple Mac End User Support Specialist) - The Star, Frisco, TX LEGENDS Founded in 2008, Legends is a premium experiences company Read more
Sr. *Apple* Engineer - Bering Straits Nativ...
…, a subsidiary of Bering Straits Native Corporation is currently seeking a qualified Sr. Apple Engineer for work in the Fort Meade, MD area. The Apple Engineer Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.