|
AppleScript and Mac OS 8.5: Introduction The new Mac OS 8.5 upgrade delivers a number of significant improvements to AppleScript. Most important among them is that AppleScript 1.3 and its suite of standard scripting additions are now almost completely PowerPC native code--this results in speed improvements of up to 400% on Power Macintosh machines. (The AppleEvent Manager, curiously, is still in 680x0 code, but will likely become native or be replaced in a future release.) A number of adjustments and improvements were made to the language itself, new scripting additions have been added, more Mac OS components have become scritpable, and a few new ways to use AppleScripts have been introduced. This workshop will go in-depth on a few of the new scripting features of Mac OS 8.5--for more information, see AppleScript Help (accessible from the Help Center menu item or in Script Editor) or the AppleScript web site.
Language ImprovementsA few improvements have been made to the language itself to better support more systems and more uses. When writing scripts in 8.5, you'll likely notice that all references to data type string are changed to plain text when the script is compiled; don't worry, this is completely "normal." Apple added the data type international text--a format for working with Unicode and non-Roman scripts that can normally be treated the same as a string--and changed the name of string to plain text to better reflect the difference. Either term can be used, and both types of strings can be treated the same way under normal circumstances.Also, a number of common units of measurement have been implemented as primitive data types; this means one can convert among units of measurement using the same methods used to coerce variable types:
18 as inches --result: inches 18.0
Obviously, attempting to convert between different classes of measurement (such as from length to volume) will return an error. You also cannot perform math with unit values; instead, convert them to matching unit types and then to numbers:
set x to 200 as grams
set x to 200 as grams
This table lists all the unit types and classes available:
(Notice that valume and liquid volume are different classes and therefore can't be converted between. Why they didn't allow the ability to convert between cubic centimeters and liters is beyond me, though.) Though the methods for dealing with dates are still a bit unwieldly, the situation has been made a bit easier by the addition ofthe built-in constants minutes, hours, days, and weeks: 60, 3600, 86400, and 604800, respectively. Since the Mac internally uses an integer number of seconds to represent date and time, these terms can be used to more easily work with relative dates by using the following style of syntax:
(current date) + 24 * hours
This example uses the idle handler (called whenever the Mac gives AppleScript a chunck of processor time and it's not executing anything else) to stop a script after 30 minutes of inactivity:
global endDate
On to New Scripting Additions and Components... |