Thanks to the following contributors (in alphabetic order):
No.The newsgroup alt.comp.lang.applescript is strictly plain text only. Please refrain from posting anything that is not plain text.
No.The newsgroup alt.comp.lang.applescript is strictly plain text only. Please refrain from posting anything that is not plain text. This includes binaries, too.
If you want to post an AppleScript, please post the source code as plain text, do not post a compiled script attached as a binary.
No, we don't.However, if you are a developer in the field of AppleScript (developing osaxen, for instance), you are welcome to advertise your latest release (and specify a download URL). This is not considered SPAM, especially if it's freeware.
In your own interest: don't do that.These are nasty, nasty things that even might lead to a reaction from your Internet Service Provider. Complaints from other Usenet users have caused ISPs to block certain people's access to the Internet and even report them to other ISPs, so they wouldn't have any access to the net anymore.
Usenet in general, and alt.comp.lang.applescript in special, is a friendly community intended to help each other out. In order to function properly, there are only a few simple rules to keep. Please do not misuse the group (or any newsgroup, for that matter).
It is okay to post a job offer like, Need AppleScripter in Boston area for design project. Will pay $100 an hour.It is not okay to ask for complete AppleScript solutions for free. The group is intended to solve problems and answer questions about AppleScript, which all subscribers will gladly help you with. But it's not there to give you something for free that actually should be paid for.
Yes, please. At least the part that gives you headache. Posting the actual script makes it much easier to help you.But don't forget to only post the source code as plain text.
Start at www.apple.com/applescript and do the Beginner's tutorial there.Later, you might want to download the AppleScript Language Guide (even though it only covers AppleScript up to version 1.3.7, most of the explanations are still valid) from the same site, and then study the scripts that came on your System CD-ROM. If you have any trouble, finish reading this FAQ now, and then post your questions to alt.comp.lang.applescript.
As for other available online resources, a good introduction is MacScripter's Magazine and Bill Briggs' Applescript Primer at Maccentral.com.
In the past couple of years, AppleScript went through quite a few updates, so, if you're looking for hardcopy books, pay attention to the year of the release.
Books from Apple Computer:
Books from third parties:
- Applescript Language Guide (PDF and HTML available online)
- ASIN: 0201407353
- Applescript Finder Guide: English Dialect
- 154 pages (July 1994) Addison-Wesley Pub Co; ISBN: 0201409100
- Applescript Scripting Additions Guide
- 116 pages (February 1994) Addison-Wesley Pub Co; ISBN: 0201407361
- Applescript in a Nutshell: A Desktop Quick Reference
- by Bruce W. Perry, 499 pages (June 2001) O'Reilly & Associates; ISBN: 1565928415
(This book is recommended by the Apple Developer Connection, and it mentions this FAQ in the Appendix)- Danny Goodman's Applescript Handbook
- by Danny Goodman; 576 pages 2nd edition (April 2000) ToExcel; ISBN: 0966551419
- Applescript for the Internet Visual Quickstart Guide
- by Ethan Wilde 339 pages 1st edition (January 15, 1999) Peachpit Press; ISBN: 0201353598
- Applescript for Applications: Visual QuickStart Guide
- by Ethan Wilde 352 pages 1 edition (November 8, 2001) Peachpit Press; ISBN: 0201716135
- Applescript for Dummies
- by Tom Trinko; 300 pages (December 21, 1995) Hungry Minds, Inc; ISBN: 1568849753
- Applied Mac Scripting (New Technology Building Blocks)
- by Tom Trinko; Book and CD-ROM edition (December 1994) Hungry Minds, Inc; ISBN: 1558283307
- The Tao of Applescript (Bmug's Guide to Macintosh Scripting)
- by Derrick Schneider, Hans Hanson; 1994, Book and 2 Disks ASIN: 1568301154
- Everyday Applescript: Connecting Applications Computers and Users
- by Christopher Allen, Book and Disk edition (June 1996) Addison-Wesley Pub Co; ISBN: 0201406713
- Applescript Applications: Building Applications With Facespan and Applescript
- by John Schettino, Liz O'Hara; ASIN: 0126239576
- AppleScripting QuarkXPress
- by Shirley Hopkins, 200 pages (November 9, 2000) DTP Connection; ISBN: 0970726503
- AppleScripting InDesign
- by Shirley Hopkins, 200 pages (December 1, 2000) DTP Connection; ISBN: 0970726511
MacScripter is currently the number one online resource. It evolved from the infamous bbs.applescript.net BBS, and today also features news on its frontpage, sample codes in the ScriptBuilders database, the multilingual MacScripter's Magazine with beginner tutorials, the web's largest Scripting Additions database osaxen.com, and a vast link collection. Whatever you don't find on that site, you will find through one of these links.Apple's official AppleScript page has news, a few beginner's tours and tutorials, sample scripts, and the latest AppleScript Language Guide. Apple also hosts a discussion board and a mailing list.
For advanced scripting, check out Bill Cheeseman's AppleScript Sourcebook. It includes in-depth discussions of techniques and a handful of valuable tips. Bill always has detailed technical reports for every new AppleScript update.
"osax" stands for "Open Scripting Architecture eXtension", and "osaxen" is simply the plural. It is also referred to as "scripting addition".Scripting additions are a means to extend the functionality of AppleScript and other languages that make use of the Open Scripting Architecture.
You can install an osax by putting it into the Scripting Additions Folder inside the System Folder (in older systems inside the Extensions Folder) or simply by dropping it onto your closed System Folder and letting the Finder do the rest.
You can download most available osaxen from MacScripter's osaxen.com.
It just means AppleScript as installed with the Mac OS - involving no applications or third-party scripting additions. By analogy with ice cream and custard: without extra flavouring or crinkly bits."French Vanilla" is a term coined by someone (probably Richard Morton) to describe Emmanuel Lévy's by now legendary method for finding the number of a month of the year: "Vanilla" because it's pure AppleScript; "French" after the nationality of its author.
Just launch Script Editor, or your favorite alternative AppleScript tool (See 2.6. Are there alternatives to Apple's Script Editor?), and choose Open Dictionary from the File menu and pick the desired application in the upcoming dialog. Script Editor will display the application's Dictionary, i.e. all supported commands and classes.If your application doesn't show up in the dialog, you can assume that the program does not support AppleScript. For ways to automate tasks with non-scriptable applications, see 2.7. What can I do if the application is not or only poorly scriptable?
Yes, there are alternative editors which differ from Script Editor in various ways. The good sides are mainly a higher functionality and better debugging features. But it usually comes for a price.Apple's Script Editor itself is installed by default whenever you install your MacOS. It lacks find-and-replace, drag-and-drop, and has a 32k limit when it comes to the maximum size of uncompiled scripts. It has a simple event window and a result window for debugging.
Scripter from Main Event gives you find-and-replace, drag-and-drop, and a highly developed debugger. Version 2.5 comes bundled with a scripting database called ScriptBase for US-$189. It also integrates well with FaceSpan. A demo can be downloaded from the Main Event web page.
Latenight Software's carbonized Script Debugger offers an extensive find-and-replace function, an elaborate user interface with drag-and-drop editing, no 32k limit, is scriptable, and besides, it sports extra tools for debugging and dictionary viewing. Current version 3.0.1 retails for US-$189. There's a save-disabled 30-day trial available for download.
Smile 1.8.4 by the French Software company Satimage is freeware, has no 32k limit, and is very well scriptable itself. It was written by Emmanuel Lévy who also contributed to this FAQ document and frequently appears in the newsgroup. Get the version you need from the Satimage download page.
For US-$ 199, Digital Technology International's interface builder FaceSpan allows you to create applications with an advanced user interface using a technology called Rapid Application Development (RAD). You can test drive the current version 3.5.2 with a 45-day trial.
The US-$ 15 shareware CLImax by Drew Thaler is not really an editor but rather a command-line interface for the Macintosh. It uses a floating window as an interface, which is always the foremost window no matter which application you might be in. Thus, you can control any scriptable program entirely with AppleScript commands from your keyboard. As it seems, development stopped with version 1.5d2, and it's not supported anymore. However, it can still be downloaded from macscripter.net.
There are ways to script applications that do not support scripting in the first place (or have a very limited AppleScript implementation). These methods usually consist of simulating mouse clicks, menu picks and keyboard input. The obvious problem with such a solution is that it has to rely on a few uncertain things, like the position of a window, the availability of a menu item etc. Another important aspect of scripting applications this way is that they have to be active (i.e. in front) for them to receive such commands, because naturally, user input (such as mouse clicks and key strokes) always goes to the active application.PreFab Player is a commercial solution that can directly access a programs menus, windows, buttons etc. It consists of an osax and a system extension. Among the most noteable features is the fact that it lets you record scripts, and that it even supports the scripting of mouse drags. You can download a 30-day trial version, the full version retails for $139.
Available freeware and shareware osaxen include Alessandro Lüthi's Sändi's Additions, and Sigma's Additions by Eric Grant. Akua Sweets also sports a few commands to control menus, the keyboard and mouse; and Akua will also let you resize windows of other apps as long as they're programmed properly.
More sophisticated solutions add real scripting to the application through a plugin or an extension. For instance, in System 7.x, the Finder was only scriptable through the Finder Scripting extension (which was installed by default, though); and Adobe Illustrator 9 ships with a scripting plugin that needs to be installed separately, and Adobe Photoshop can be extensively scripted with Mainevent's PhotoScripter.
Oh boy, quite a few. Here is a more or less complete list of discussions, mailing lists and BBS's (apart from our beloved newsgroup):
- Apple's AppleScript Users mailing list for scripters developing scripts and solutions in AppleScript
- Apple's AppleScript Implementors mailing list for programmers creating scriptable applications and OSA languages
- Apple's discussion board (you need to register an AppleID first)
- Dartmouth College's MACSCRPT mailing list on Macintosh scripting (alternate archive hosted by the University of Melbourne, Australia)
- MacScripter's moderated bbs.applescript.net Scripting Discussion Board
- The Philadelphia Area AppleScript User's Group maintains the PA-ASUG mailing list
The number one mistake we've seen is to forget the proper "tell" statement. E.g. if you wanna fetch the creation date of a file on the desktop:creation date of file "myFile"...won't do much for you, except give you a runtime error, even though everything seems to be correct. It needs to be:tell application "Finder" creation date of file "myFile" end tellNever forget which application you are telling to do what. Unless it's a standard command or within one of the installed Scripting Additions (osaxen), you need a "tell application ..." command.
tell application "Finder" select file "myFile" set position of selection to {948, 571} end tellSince OS 9, this script won't work as long as the "snap to grid" option is turned on in the Finder Preferences. A potential workaround is to turn it off:tell application "Finder" set SVA_preferences to spatial view arrangement of the desktop --saves the current settings set spatial view arrangement of the desktop to not arranged set position of file "myFile" to {948, 571} set spatial view arrangement of the desktop to SVA_preferences --restores the desktop settings end tellIn order to restore the Finder Preferences to their original settings, they were saved in the SVA_preferences variable.A second possibility to circumvent the positioning problem is to use the move command instead. This solution works no matter what your Finder preferences are:
tell application "Finder" move file "myFile" to desktop positioned at {948, 571} end tell
AppleScript's date object gives you the month as a string only (January, February etc.). You can either now check for the string value of the month and get the appropriate number through a series of 12 "if...then" loops, or you can use the so-called French Vanilla algorithm:set theDate to the current date --or any other date copy theDate to b set the month of b to January set monthNum to (1 + (theDate - b + 1314864) div 2629728)The variable monthNum will return an integer representing the number of the month (1 through 12).
The following recursive subroutine will take any list as parameter and return it sorted in ascending order.
on sort(l) if length of l = 1 then return l set x to item 1 of l set ll to rest of l set l1 to {} set l2 to {} repeat with i in ll if x < i then set l2 to l2 & i else set l1 to l1 & i end if end repeat if length of l1 > 1 then set l1 to sort(l1) if length of l2 > 1 then set l2 to sort(l2) return l1 & x & l2 end sortIf you want a descending order, use "if x>i" instead of "if x<i" in the eighth line. This sorting routine works on strings as well as on numbers.
The simplest way to do this would be:
tell application "Finder" delete (every file of myFolder whose modification date comes before ((current date) - 7 * days)) end tellUnfortunately, this doesn't work because of a bug which makes this construction give erratic results with numeric tests (such as modification dates). The alternative is to use a loop, which is much slower. However, the process can be speeded up if you use the Standard Additions instead of the Finder to identify old items and then use the Finder to delete the files amongst them all in one go at the end:-- Choose the folder set myFolder to choose folder -- the result is an 'alias' to the folder set myPath to myFolder as string -- but the 'string' form is also needed -- Set the cutoff date and time set aWeekAgo to the (current date) - 1 * weeks -- Use Standard Additions commands to identify items over a week old set theItemNames to (list folder myFolder without invisibles) set theDeleteList to {} repeat with thisName in theItemNames set theFullPath to alias (myPath & thisName) set theInfo to info for theFullPath if the modification date of theInfo comes before aWeekAgo then set the end of theDeleteList to thisName end if end repeat -- Use the Finder to delete all the old files (only) at once tell the application "Finder" delete (every file of myFolder whose name is in theDeleteList) end tellTo delete old files in all the subfolders of the selected folder, a recursive script is required. Note that there is a call to the handler within the handler itself.deleteOldFiles(choose folder, (current date) - 1 * weeks) on deleteOldFiles(thisFolder, cutoffDate) set fldrPath to thisFolder as string -- Use Standard Additions commands to identify old files set theDeathList to {} repeat with thisName in (list folder thisFolder without invisibles) set thisItem to alias (fldrPath & thisName) set theInfo to info for thisItem -- If an item's a folder then recurse through it -- Otherwise, check the modification date if theInfo's folder then deleteOldFiles(thisItem, cutoffDate) else if theInfo's modification date comes before cutoffDate then set the end of theDeathList to thisName end if end repeat -- Use the Finder to delete all the old files in each folder at once tell the application "Finder" delete (every file of thisFolder whose name is in theDeathList) end tell end deleteOldFiles
tell application "Finder" return bounds of content space of desktop end tell...will return the bounding rectangle of the desktop, minus the menu bar, in global coordinates.
When saving the script, uncheck the box that says, "Show Startup Window". This is a feature that allows you to give another user a second chance to decide whether he or she really wants to run the script or not.
Ask the Finder for a list of its processes:tell application "Finder" to name of processes...will list each running app's name. Leaving off the "name of" part will give you a list with items like process "MacSOUP" of application "Finder". You can also find out the number of currently running processes by checking for the length of the returned list:tell application "Finder" to length of (processes as list)Keep in mind that the "processes" command also includes invisible background processes like the time sync extension and the Folder Actions.
The Finder doesn't have a "hide" command, but the "process" class has a "visible" flag, which you can define as false. Make sure that there's at least one other application visible.tell application "Finder" set the visible of process "Eudora" to false end tell
Yes. But you can't tell the Finder to do so. You have to "tell" the Folder Actions extension in your Extensions Folder (inside your System Folder) directly:tell application "Folder Actions Extension" attach action to "Macintosh HD:Desktop Folder:My Folder:" using "Macintosh HD:My Scripts:My Folder Action" end tellBe aware that the name of the extension might vary depending on the language of your Mac OS. You will have to adjust the first line of the tell block accordingly.
You probably have AppleScript version 1.5.5, which originally shipped with MacOS 9.1. The Standard Additions commands regarding opening, reading from, writing to, and closing a file are rather buggy in this very version. For instance, the optional using delimiters parameter of the read command simply does not work.If you want to keep OS 9.1, we recommend that you upgrade to AppleScript version 1.6, or just upgrade your whole system to MacOS 9.2.1. For more detailed information regarding this topic, see Bill Cheeseman's reports on AppleScript since version 1.1.2.