Smashing Newsletter
Every week, we send out useful front-end & UX techniques. Subscribe and get the Smart Interface Design Checklists PDF delivered to your inbox.
If you are an experienced professional, chances are you have a good set of tools and a work process that you repeat on a daily basis to handle your work. That's good; it's how you become more productive, and become an expert. But with repetitive processes come repetitive mechanical work. Whether it's opening a file in Photoshop to change the format or adding an iCal to-do item based on an email you received, these little tasks can be streamlined. That's the purpose of AppleScripts.
As a result, despite being with us for nearly 30 years, AppleScript is barely used by the majority of Mac admins, Mac developers or Mac end users. Indeed, AppleScript may have a good claim to being the Most Unloved and Unlovable Programming Language Ever. It helps you to explore, manipulate and monitor the User Interface elements of most Mac OS X applications running on your computer. Smile is a programming and working environment based on AppleScript. In Smile you edit AppleScripts, and much more. Training and Services. AppleScript 1-2-3 is the Apple Training Series book for AppleScript.
Starting with macOS 10.14 (Mojave), the OS will show a warning when an AppleScript tries to control some applications. It is not the case for all Applications. This video tutorial is about how to use AppleScripts. For those of you who do not know how to use Applescript examples or sources you find online, this is the video for you. So go make some programs on your Mac computer, and create your own scripts, with Script Editor. The AppleScripts contain the instructions for the task you want the other Mac to perform while the AE Server authorizes and executes the instructions. You can tell another Mac to shut down, play a song, visit a website, or display an alert using these features.
AppleScript is a scripting language developed by Apple to help people automate their work processes on the Mac operating system. It accomplishes this by exposing every element of the system's applications as an object in an extremely simple, English-like language. AppleScript is to the Mac OS as JavaScript is to browsers.
You may also be interested in the following related posts:
Quite a few AppleScripts are available on the Web, ready for you to use, so you don't even need to look at their code. This article presents you with 17 of the most useful ones.
If you're interested in learning this language, here are some good resources to get started:
- Official AppleScript Website Apple's page on AppleScript.
- AppleScript Language Guide Apple's in-depth guide to AppleScript.
- Learning AppleScript Macworld's article on the fundamentals of writing AppleScripts.
- AppleScript Users AppleScript Mailing List.
First, Where To Put Your AppleScripts
After you download a script, you have to know where to put it to start using it. For this purpose, let's say that there are three different kinds of AppleScripts, each of which is used for a different purpose.
Simple Scripts
You put these scripts in a special folder and call them when you need them. You can invoke them just by double clicking on them, but calling them contextually is a lot more effective. Using the Script Menu is one way to achieve this.
To activate the Script Menu, first open the AppleScript Utility app in the /Applications/AppleScript folder and check 'Show Script Menu in menu bar.'
The Script Menu will show a list of AppleScripts that come with Mac OS X, plus your application-specific scripts. To add a script to an application, simply put it in ~/Library/Scripts/Applications/. If that folder doesn't exist, you can create it.
For example, if you had a Safari AppleScript, you'd put it in ~/Library/Scripts/Applications/Safari. From then on, if you clicked the Script Menu when Safari was active, your script would appear at the top of the list for you to use. Nokia for mac os x suite.
Droplets
Droplets are AppleScripts that live in the Finder's toolbar. To use it, all you need to do is drop a file or folder into it. This is very useful for when a script affects a file or the contents of a folder, because all you have to do is drop the target of the action onto the script's icon.
To 'install' a Droplet, first save it in a folder of your choosing: ~/Library/Scripts/Droplets is a good place. Then just drag the script to the Finder's toolbar.
Folder Actions
Folder Actions are AppleScripts that are 'attached' to a folder. They are executed every time you perform an action with that folder. Folder Actions can get triggered every time you add a file to a folder, remove a file, modify its items, etc. The behavior depends on how the script works, but you can imagine how useful that would be.
To add a Folder Action to a folder, right-click it to bring up the contextual menu, and click Attach a Folder Action. The default location for Folder Action scripts is /Library/Scripts/Folder Action Scripts, but if you want to keep all your custom-installed scripts in one place, ~/Library/Scripts/Folder Actions is a good place to keep them.
Multimedia Processing
1. ConvertImage
This is a great example of how Droplets are useful. Just drop an image file into ConvertImage, and you will be prompted to choose from a list of file formats. Pick a format, and it saves it in the same folder as your original file.
ConvertImageType: DropletRequirements: OS X 10.4+, Image Events
2. QuickTime to Photoshop
Exports QuickTime frames directly to Photoshop. All you have to do is pause a video at the frame that you want to export, and then invoke the script. If Photoshop is closed, the script will activate it for you. After it imports the frame, it will ask you if you want another frame from the QuickTime file.
QuickTime to Photoshop
Type: Simple ScriptRequirements: Adobe Photoshop CS4
3. iPhoto to Photoshop
This opens the currently selected iPhoto image in Photoshop. It is a simple automation leap that gets you where you want without intervening steps.
iPhoto to Photoshop
Type: Simple ScriptRequirements: Adobe Photoshop CS4
4. Rampage
Drop an image file or a folder with image files in Rampage, and you get a text file with a lot of information about the file(s): size, resolution, color mode, ICC Profiles and more. It also reports warnings and errors about the file(s). The script currently supports TIFF, GIF, BMP, PNG and JPG image formats.
RampageType: DropletRequirements: None
5. SWF Extractor
This extract SWF files from Flash projectors (Windows or Mac executables) that are dropped into it.
SWF ExtractorType: DropletRequirements: None
Safari Tools
6. Safari Web Site Validator
Safari Web Site Validator gets the HTML or XHTML from the current active Safari tab and sends the code to the W3C Markup Validation Service in a separate window. It then asks if you want to validate the page's CSS file as well.
Safari Web Site ValidatorType: Simple ScriptsRequirements: OS X 10.4.4+
7. Tiny URL
Despite its name, the Tiny URL script doesn't use the TinyUrl application. It's based on another URL shortening service called Metamark. It goes to the currently active Safari tab and puts the shortened URL directly in your clipboard.
Tiny URLType: Simple ScriptsRequirements: None
8. Safari Cleannup
This automates the deletion of Safari icons and cache and plist files. Getting rid of these extraneous files can boost Safari's performance.
Safari CleannupType: Simple ScriptsRequirements: None
9. Scour Web Page
This script scans the current Web page in Safari looking for MP3, AAC and PDF media files. If it finds multiple files, it prompts you to select the ones you want to keep, and then downloads them and adds them to your iTunes media library.
Scour Web Page
Type: Simple ScriptsRequirements: None
Mail And iCal
10. Fuhgeddaboutit
In Sopranos-speak, fuhgeddaboutit means 'forget about it.' Indeed, one of the purposes of GTD is to free your brain from having to keep track of everything. Just relax, forget about it now and be confident that you'll remember when you need to.
This script make that possible by making iCal To-Do items from an Apple Mail email. Just invoke the script with the email you want, and it will create an iCal item with a due time set relative to the email's arrival.
FuhgeddaboutitType: Simple ScriptsRequirements: None
11. Send Attachment Droplet
Just drop a file into this Droplet, and it will make a new Mail email with the file as an attachment and the subject set to the file's name. If the Mail app is closed, the script will open it for you.
Send Attatchment DropletType: DropletRequirements: None
12. Remove iCal Duplicates
When you sync and share many calendars in iCal, you often end up with a lot of duplicates. This simple script helps you remove those. But once you ask it to delete duplicates, there's no undoing. So, be sure to back up your calendar first.
Remove iCal DuplicatesType: Simple ScriptRequirements: None
13. iCalculate
Invoke this script, create an iCal calendar item and start date, and it will generate a text file reporting how many hours you have worked on the project. It even calculates the total cost of the project, based on the hourly rate your specify. Especially suited to freelancers.
iCalculateType: Simple ScriptRequirements: None
Finder Utilities
14. Pack'em
Pack'em takes one or more items from Finder, packs them with tar, compresses them with either bzip2 or gzip and saves the compressed archive in the same folder as the original items. A great companion to the Send Attachment Droplet. With these two AppleScripts, you can compress and email a set of files or folders directly from Finder.
Pack'emType: Simple ScriptRequirements: None
15. Rename Files
Just drop a folder into this Droplet, and it will give you a lot of options to batch process its contents. You can rename the files according to names specified in a particular text file or change the files individually. Either way accomplishes your task much faster than by changing every file name independently.
Rename FilesType: DropletRequirements: None
16. Websafe Name
If you develop websites, you are probably accustomed to giving your files Web-friendly names. But there are times when you have to upload a whole set of files sent to you by a client, or upload things that you weren't expecting to use. Websafe Name is very useful for this kind of task. You don't even need to look through the list of files; just drop them into this script, and it will rename them to something Web-friendly.
Websafe NameType: DropletRequirements: None
17. Tagger
Safari Web Site Validator gets the HTML or XHTML from the current active Safari tab and sends the code to the W3C Markup Validation Service in a separate window. It then asks if you want to validate the page's CSS file as well.
Safari Web Site ValidatorType: Simple ScriptsRequirements: OS X 10.4.4+
7. Tiny URL
Despite its name, the Tiny URL script doesn't use the TinyUrl application. It's based on another URL shortening service called Metamark. It goes to the currently active Safari tab and puts the shortened URL directly in your clipboard.
Tiny URLType: Simple ScriptsRequirements: None
8. Safari Cleannup
This automates the deletion of Safari icons and cache and plist files. Getting rid of these extraneous files can boost Safari's performance.
Safari CleannupType: Simple ScriptsRequirements: None
9. Scour Web Page
This script scans the current Web page in Safari looking for MP3, AAC and PDF media files. If it finds multiple files, it prompts you to select the ones you want to keep, and then downloads them and adds them to your iTunes media library.
Scour Web Page
Type: Simple ScriptsRequirements: None
Mail And iCal
10. Fuhgeddaboutit
In Sopranos-speak, fuhgeddaboutit means 'forget about it.' Indeed, one of the purposes of GTD is to free your brain from having to keep track of everything. Just relax, forget about it now and be confident that you'll remember when you need to.
This script make that possible by making iCal To-Do items from an Apple Mail email. Just invoke the script with the email you want, and it will create an iCal item with a due time set relative to the email's arrival.
FuhgeddaboutitType: Simple ScriptsRequirements: None
11. Send Attachment Droplet
Just drop a file into this Droplet, and it will make a new Mail email with the file as an attachment and the subject set to the file's name. If the Mail app is closed, the script will open it for you.
Send Attatchment DropletType: DropletRequirements: None
12. Remove iCal Duplicates
When you sync and share many calendars in iCal, you often end up with a lot of duplicates. This simple script helps you remove those. But once you ask it to delete duplicates, there's no undoing. So, be sure to back up your calendar first.
Remove iCal DuplicatesType: Simple ScriptRequirements: None
13. iCalculate
Invoke this script, create an iCal calendar item and start date, and it will generate a text file reporting how many hours you have worked on the project. It even calculates the total cost of the project, based on the hourly rate your specify. Especially suited to freelancers.
iCalculateType: Simple ScriptRequirements: None
Finder Utilities
14. Pack'em
Pack'em takes one or more items from Finder, packs them with tar, compresses them with either bzip2 or gzip and saves the compressed archive in the same folder as the original items. A great companion to the Send Attachment Droplet. With these two AppleScripts, you can compress and email a set of files or folders directly from Finder.
Pack'emType: Simple ScriptRequirements: None
15. Rename Files
Just drop a folder into this Droplet, and it will give you a lot of options to batch process its contents. You can rename the files according to names specified in a particular text file or change the files individually. Either way accomplishes your task much faster than by changing every file name independently.
Rename FilesType: DropletRequirements: None
16. Websafe Name
If you develop websites, you are probably accustomed to giving your files Web-friendly names. But there are times when you have to upload a whole set of files sent to you by a client, or upload things that you weren't expecting to use. Websafe Name is very useful for this kind of task. You don't even need to look through the list of files; just drop them into this script, and it will rename them to something Web-friendly.
Websafe NameType: DropletRequirements: None
17. Tagger
The 'folder' is a computer interface paradigm that is a very powerful way to organize files. But it's neither the only paradigm nor the best solution for all scenarios. Many sub-folders nested deep is a sign that a folder structure may not be appropriate. Another great paradigm, coming straight from the Web, is 'tagging.' You keep all your files flat in a common location, but group them by tags so that you can retrieve or filter them by tags. It so happens that the Mac OS X has very good support for this. You can use Spotlight Comments to tag files and Smart Folders to dynamically retrieve them. All you need now is an easy way to do this, and this Folder Action does exactly that.
To use Tagger, attach it to a folder. Then, every time you add a file to that folder via Finder, the script will prompt you to tag that file. It also automatically creates Smart Folders for all of your defined tags.
Applescript For Each
TaggerType: Folder ActionRequirements: None
Further Resources
If you like the scripts above, you may also be interested in the following articles and related resources:
- Automation Life Hacks You Can't Live Without Eight automation life hacks for home, work, and life in general. No coding skills required.
- Doug's AppleScripts for iTunes A huge collection of AppleScripts for iTunes.
- Studio Log Scripts and discussion on how to make them.
- AppleScripts on Github A search list of AppleScripts hosted on Github
This document is a guide to the AppleScript language—its lexical conventions, syntax, keywords, and other elements. It is intended primarily for use with AppleScript 2.0 or later and macOS version 10.5 or later.
AppleScript 2.0 can use scripts developed for any version of AppleScript from 1.1 through 1.10.7, any scripting addition created for AppleScript 1.5 or later for macOS, and any scriptable application for Mac OS v7.1 or later. A script created with AppleScript 2.0 can be used by any version of AppleScript back to version 1.1, provided it does not use features of AppleScript, scripting additions, or scriptable applications that are unavailable in that version.
Important: Descriptions and examples for the terms in this document have been tested with AppleScript 2.0 in OS X v10.5 (Leopard). Except for terms that are noted as being new in Leopard, most descriptions and examples work with previous system versions, but have not been tested against all of them.
If you need detailed information about prior system and AppleScript versions, see AppleScript Release Notes (OS X v10.4 and earlier).
What Is AppleScript?
AppleScript is a scripting language created by Apple. It allows users to directly control scriptable Macintosh applications, as well as parts of macOS itself. You can create scripts—sets of written instructions—to automate repetitive tasks, combine features from multiple scriptable applications, and create complex workflows.
Note: Apple also provides the Automator application, which allows users to automate common tasks by hooking together ready-made actions in a graphical environment. For more information, see Automator Documentation.
A scriptable application is one that can be controlled by a script. For AppleScript, that means being responsive to interapplication messages, called Apple events, sent when a script command targets the application. (Apple events can also be sent directly from other applications and macOS.)
AppleScript itself provides a very small number of commands, but it provides a framework into which you can plug many task-specific commands—those provided by scriptable applications and scriptable parts of macOS.
Most script samples and script fragments in this guide use scriptable features of the Finder application, scriptable parts of macOS, or scriptable applications distributed with macOS, such as TextEdit (located in /Applications
).
Who Should Read This Document?
You should use this document if you write or modify AppleScript scripts, or if you create scriptable applications and need to know how scripts should work.
AppleScript Language Guide assumes you are familiar with the high-level information about AppleScript found in AppleScript Overview.
Organization of This Document
This guide describes the AppleScript language in a series of chapters and appendixes.
The first five chapters introduce components of the language and basic concepts for using it, then provide additional overview on working with script objects and handler routines:
How To Use Applescript
AppleScript Lexical Conventions describes the characters, symbols, keywords, and other language elements that make up statements in an AppleScript script.
AppleScript Fundamentals describes basic concepts that underly the terminology and rules covered in the rest of this guide.
Variables and Properties describes common issues in working with variables and properties, including how to declare them and how AppleScript interprets their scope.
Script Objects describes how to define, initialize, send commands to, and use inheritance with script objects.
About Handlers provides information on using handlers (a type of function available in AppleScript) to factor and reuse code.
The following chapters provide reference for the AppleScript Language:
Class Reference describes the classes AppleScript defines for common objects used in scripts.
Commands Reference describes the commands that are available to any script.
Reference Forms describes the syntax for specifying an object or group of objects in an application or other container.
Operators Reference provides a list of the operators AppleScript supports and the rules for using them, along with sections that provide additional detail for commonly used operators.
Control Statements Reference describes statements that control when and how other statements are executed. It covers standard conditional statements, as well as statements used in error handling and other operations.
Handler Reference shows the syntax for defining and calling handlers and describes other statements you use with handlers.
The following chapter describes an AppleScript-related feature of macOS:
Folder Actions Reference describes how you can write and attach script handlers to specific folders, such that the handlers are invoked when the folders are modified.
The following appendixes provide additional information about the AppleScript language and how to work with errors in scripts:
AppleScript Keywords lists the keywords of the AppleScript language, provides a brief description for each, and points to related information.
Error Numbers and Error Messages describes error numbers and error messages you may see in working with AppleScript scripts.
Working with Errors provides detailed examples of handling errors with try Statements and error Statements.
Double Angle Brackets describes when you are likely to see double angle brackets (or chevrons—
«»
) in scripts and how you can work with them.Libraries using Load Script describes how to save libraries of handlers and access them from other scripts.
Unsupported Terms lists terms that are no longer supported in AppleScript.
Conventions Used in This Guide
Glossary terms are shown in boldface where they are defined.
Important: This document sometimes uses the continuation character (¬) for sample statements that don't fit on one line on a document page. It also uses the continuation character in some syntax statements to identify an item that, if included, must appear on the same line as the previous item. The continuation character itself is not a required part of the syntax—it is merely a mechanism for including multiple lines in one statement.
The following conventions are used in syntax descriptions:
| Plain computer font indicates an element that you type exactly as shown. If there are special symbols (for example, |
placeholder | Italic text indicates a placeholder that you replace with an appropriate value. |
[optional] | Brackets indicate that the enclosed language element or elements are optional. |
(a group) | Parentheses group elements together. However, the parentheses shown in Handler Syntax (Positional Parameters) are part of the syntax. |
[optional].. | Three ellipsis points (..) after a group defined by brackets indicate that you can repeat the group of elements within brackets 0 or more times. |
a | b | c | Vertical bars separate elements in a group from which you must choose a single element. The elements are often grouped within parentheses or brackets. |
Filenames shown in scripts | Most filenames shown in examples in this document include extensions, such as To work with the examples on your computer, you may need to modify either that setting or the filenames. |
Script Editor Mac
To activate the Script Menu, first open the AppleScript Utility app in the /Applications/AppleScript folder and check 'Show Script Menu in menu bar.'
The Script Menu will show a list of AppleScripts that come with Mac OS X, plus your application-specific scripts. To add a script to an application, simply put it in ~/Library/Scripts/Applications/. If that folder doesn't exist, you can create it.
For example, if you had a Safari AppleScript, you'd put it in ~/Library/Scripts/Applications/Safari. From then on, if you clicked the Script Menu when Safari was active, your script would appear at the top of the list for you to use. Nokia for mac os x suite.
Droplets
Droplets are AppleScripts that live in the Finder's toolbar. To use it, all you need to do is drop a file or folder into it. This is very useful for when a script affects a file or the contents of a folder, because all you have to do is drop the target of the action onto the script's icon.
To 'install' a Droplet, first save it in a folder of your choosing: ~/Library/Scripts/Droplets is a good place. Then just drag the script to the Finder's toolbar.
Folder Actions
Folder Actions are AppleScripts that are 'attached' to a folder. They are executed every time you perform an action with that folder. Folder Actions can get triggered every time you add a file to a folder, remove a file, modify its items, etc. The behavior depends on how the script works, but you can imagine how useful that would be.
To add a Folder Action to a folder, right-click it to bring up the contextual menu, and click Attach a Folder Action. The default location for Folder Action scripts is /Library/Scripts/Folder Action Scripts, but if you want to keep all your custom-installed scripts in one place, ~/Library/Scripts/Folder Actions is a good place to keep them.
Multimedia Processing
1. ConvertImage
This is a great example of how Droplets are useful. Just drop an image file into ConvertImage, and you will be prompted to choose from a list of file formats. Pick a format, and it saves it in the same folder as your original file.
ConvertImageType: DropletRequirements: OS X 10.4+, Image Events
2. QuickTime to Photoshop
Exports QuickTime frames directly to Photoshop. All you have to do is pause a video at the frame that you want to export, and then invoke the script. If Photoshop is closed, the script will activate it for you. After it imports the frame, it will ask you if you want another frame from the QuickTime file.
QuickTime to Photoshop
Type: Simple ScriptRequirements: Adobe Photoshop CS4
3. iPhoto to Photoshop
This opens the currently selected iPhoto image in Photoshop. It is a simple automation leap that gets you where you want without intervening steps.
iPhoto to Photoshop
Type: Simple ScriptRequirements: Adobe Photoshop CS4
4. Rampage
Drop an image file or a folder with image files in Rampage, and you get a text file with a lot of information about the file(s): size, resolution, color mode, ICC Profiles and more. It also reports warnings and errors about the file(s). The script currently supports TIFF, GIF, BMP, PNG and JPG image formats.
RampageType: DropletRequirements: None
5. SWF Extractor
This extract SWF files from Flash projectors (Windows or Mac executables) that are dropped into it.
SWF ExtractorType: DropletRequirements: None
Safari Tools
6. Safari Web Site Validator
Safari Web Site Validator gets the HTML or XHTML from the current active Safari tab and sends the code to the W3C Markup Validation Service in a separate window. It then asks if you want to validate the page's CSS file as well.
Safari Web Site ValidatorType: Simple ScriptsRequirements: OS X 10.4.4+
7. Tiny URL
Despite its name, the Tiny URL script doesn't use the TinyUrl application. It's based on another URL shortening service called Metamark. It goes to the currently active Safari tab and puts the shortened URL directly in your clipboard.
Tiny URLType: Simple ScriptsRequirements: None
8. Safari Cleannup
This automates the deletion of Safari icons and cache and plist files. Getting rid of these extraneous files can boost Safari's performance.
Safari CleannupType: Simple ScriptsRequirements: None
9. Scour Web Page
This script scans the current Web page in Safari looking for MP3, AAC and PDF media files. If it finds multiple files, it prompts you to select the ones you want to keep, and then downloads them and adds them to your iTunes media library.
Scour Web Page
Type: Simple ScriptsRequirements: None
Mail And iCal
10. Fuhgeddaboutit
In Sopranos-speak, fuhgeddaboutit means 'forget about it.' Indeed, one of the purposes of GTD is to free your brain from having to keep track of everything. Just relax, forget about it now and be confident that you'll remember when you need to.
This script make that possible by making iCal To-Do items from an Apple Mail email. Just invoke the script with the email you want, and it will create an iCal item with a due time set relative to the email's arrival.
FuhgeddaboutitType: Simple ScriptsRequirements: None
11. Send Attachment Droplet
Just drop a file into this Droplet, and it will make a new Mail email with the file as an attachment and the subject set to the file's name. If the Mail app is closed, the script will open it for you.
Send Attatchment DropletType: DropletRequirements: None
12. Remove iCal Duplicates
When you sync and share many calendars in iCal, you often end up with a lot of duplicates. This simple script helps you remove those. But once you ask it to delete duplicates, there's no undoing. So, be sure to back up your calendar first.
Remove iCal DuplicatesType: Simple ScriptRequirements: None
13. iCalculate
Invoke this script, create an iCal calendar item and start date, and it will generate a text file reporting how many hours you have worked on the project. It even calculates the total cost of the project, based on the hourly rate your specify. Especially suited to freelancers.
iCalculateType: Simple ScriptRequirements: None
Finder Utilities
14. Pack'em
Pack'em takes one or more items from Finder, packs them with tar, compresses them with either bzip2 or gzip and saves the compressed archive in the same folder as the original items. A great companion to the Send Attachment Droplet. With these two AppleScripts, you can compress and email a set of files or folders directly from Finder.
Pack'emType: Simple ScriptRequirements: None
15. Rename Files
Just drop a folder into this Droplet, and it will give you a lot of options to batch process its contents. You can rename the files according to names specified in a particular text file or change the files individually. Either way accomplishes your task much faster than by changing every file name independently.
Rename FilesType: DropletRequirements: None
16. Websafe Name
If you develop websites, you are probably accustomed to giving your files Web-friendly names. But there are times when you have to upload a whole set of files sent to you by a client, or upload things that you weren't expecting to use. Websafe Name is very useful for this kind of task. You don't even need to look through the list of files; just drop them into this script, and it will rename them to something Web-friendly.
Websafe NameType: DropletRequirements: None
17. Tagger
Safari Web Site Validator gets the HTML or XHTML from the current active Safari tab and sends the code to the W3C Markup Validation Service in a separate window. It then asks if you want to validate the page's CSS file as well.
Safari Web Site ValidatorType: Simple ScriptsRequirements: OS X 10.4.4+
7. Tiny URL
Despite its name, the Tiny URL script doesn't use the TinyUrl application. It's based on another URL shortening service called Metamark. It goes to the currently active Safari tab and puts the shortened URL directly in your clipboard.
Tiny URLType: Simple ScriptsRequirements: None
8. Safari Cleannup
This automates the deletion of Safari icons and cache and plist files. Getting rid of these extraneous files can boost Safari's performance.
Safari CleannupType: Simple ScriptsRequirements: None
9. Scour Web Page
This script scans the current Web page in Safari looking for MP3, AAC and PDF media files. If it finds multiple files, it prompts you to select the ones you want to keep, and then downloads them and adds them to your iTunes media library.
Scour Web Page
Type: Simple ScriptsRequirements: None
Mail And iCal
10. Fuhgeddaboutit
In Sopranos-speak, fuhgeddaboutit means 'forget about it.' Indeed, one of the purposes of GTD is to free your brain from having to keep track of everything. Just relax, forget about it now and be confident that you'll remember when you need to.
This script make that possible by making iCal To-Do items from an Apple Mail email. Just invoke the script with the email you want, and it will create an iCal item with a due time set relative to the email's arrival.
FuhgeddaboutitType: Simple ScriptsRequirements: None
11. Send Attachment Droplet
Just drop a file into this Droplet, and it will make a new Mail email with the file as an attachment and the subject set to the file's name. If the Mail app is closed, the script will open it for you.
Send Attatchment DropletType: DropletRequirements: None
12. Remove iCal Duplicates
When you sync and share many calendars in iCal, you often end up with a lot of duplicates. This simple script helps you remove those. But once you ask it to delete duplicates, there's no undoing. So, be sure to back up your calendar first.
Remove iCal DuplicatesType: Simple ScriptRequirements: None
13. iCalculate
Invoke this script, create an iCal calendar item and start date, and it will generate a text file reporting how many hours you have worked on the project. It even calculates the total cost of the project, based on the hourly rate your specify. Especially suited to freelancers.
iCalculateType: Simple ScriptRequirements: None
Finder Utilities
14. Pack'em
Pack'em takes one or more items from Finder, packs them with tar, compresses them with either bzip2 or gzip and saves the compressed archive in the same folder as the original items. A great companion to the Send Attachment Droplet. With these two AppleScripts, you can compress and email a set of files or folders directly from Finder.
Pack'emType: Simple ScriptRequirements: None
15. Rename Files
Just drop a folder into this Droplet, and it will give you a lot of options to batch process its contents. You can rename the files according to names specified in a particular text file or change the files individually. Either way accomplishes your task much faster than by changing every file name independently.
Rename FilesType: DropletRequirements: None
16. Websafe Name
If you develop websites, you are probably accustomed to giving your files Web-friendly names. But there are times when you have to upload a whole set of files sent to you by a client, or upload things that you weren't expecting to use. Websafe Name is very useful for this kind of task. You don't even need to look through the list of files; just drop them into this script, and it will rename them to something Web-friendly.
Websafe NameType: DropletRequirements: None
17. Tagger
The 'folder' is a computer interface paradigm that is a very powerful way to organize files. But it's neither the only paradigm nor the best solution for all scenarios. Many sub-folders nested deep is a sign that a folder structure may not be appropriate. Another great paradigm, coming straight from the Web, is 'tagging.' You keep all your files flat in a common location, but group them by tags so that you can retrieve or filter them by tags. It so happens that the Mac OS X has very good support for this. You can use Spotlight Comments to tag files and Smart Folders to dynamically retrieve them. All you need now is an easy way to do this, and this Folder Action does exactly that.
To use Tagger, attach it to a folder. Then, every time you add a file to that folder via Finder, the script will prompt you to tag that file. It also automatically creates Smart Folders for all of your defined tags.
Applescript For Each
TaggerType: Folder ActionRequirements: None
Further Resources
If you like the scripts above, you may also be interested in the following articles and related resources:
- Automation Life Hacks You Can't Live Without Eight automation life hacks for home, work, and life in general. No coding skills required.
- Doug's AppleScripts for iTunes A huge collection of AppleScripts for iTunes.
- Studio Log Scripts and discussion on how to make them.
- AppleScripts on Github A search list of AppleScripts hosted on Github
This document is a guide to the AppleScript language—its lexical conventions, syntax, keywords, and other elements. It is intended primarily for use with AppleScript 2.0 or later and macOS version 10.5 or later.
AppleScript 2.0 can use scripts developed for any version of AppleScript from 1.1 through 1.10.7, any scripting addition created for AppleScript 1.5 or later for macOS, and any scriptable application for Mac OS v7.1 or later. A script created with AppleScript 2.0 can be used by any version of AppleScript back to version 1.1, provided it does not use features of AppleScript, scripting additions, or scriptable applications that are unavailable in that version.
Important: Descriptions and examples for the terms in this document have been tested with AppleScript 2.0 in OS X v10.5 (Leopard). Except for terms that are noted as being new in Leopard, most descriptions and examples work with previous system versions, but have not been tested against all of them.
If you need detailed information about prior system and AppleScript versions, see AppleScript Release Notes (OS X v10.4 and earlier).
What Is AppleScript?
AppleScript is a scripting language created by Apple. It allows users to directly control scriptable Macintosh applications, as well as parts of macOS itself. You can create scripts—sets of written instructions—to automate repetitive tasks, combine features from multiple scriptable applications, and create complex workflows.
Note: Apple also provides the Automator application, which allows users to automate common tasks by hooking together ready-made actions in a graphical environment. For more information, see Automator Documentation.
A scriptable application is one that can be controlled by a script. For AppleScript, that means being responsive to interapplication messages, called Apple events, sent when a script command targets the application. (Apple events can also be sent directly from other applications and macOS.)
AppleScript itself provides a very small number of commands, but it provides a framework into which you can plug many task-specific commands—those provided by scriptable applications and scriptable parts of macOS.
Most script samples and script fragments in this guide use scriptable features of the Finder application, scriptable parts of macOS, or scriptable applications distributed with macOS, such as TextEdit (located in /Applications
).
Who Should Read This Document?
You should use this document if you write or modify AppleScript scripts, or if you create scriptable applications and need to know how scripts should work.
AppleScript Language Guide assumes you are familiar with the high-level information about AppleScript found in AppleScript Overview.
Organization of This Document
This guide describes the AppleScript language in a series of chapters and appendixes.
The first five chapters introduce components of the language and basic concepts for using it, then provide additional overview on working with script objects and handler routines:
How To Use Applescript
AppleScript Lexical Conventions describes the characters, symbols, keywords, and other language elements that make up statements in an AppleScript script.
AppleScript Fundamentals describes basic concepts that underly the terminology and rules covered in the rest of this guide.
Variables and Properties describes common issues in working with variables and properties, including how to declare them and how AppleScript interprets their scope.
Script Objects describes how to define, initialize, send commands to, and use inheritance with script objects.
About Handlers provides information on using handlers (a type of function available in AppleScript) to factor and reuse code.
The following chapters provide reference for the AppleScript Language:
Class Reference describes the classes AppleScript defines for common objects used in scripts.
Commands Reference describes the commands that are available to any script.
Reference Forms describes the syntax for specifying an object or group of objects in an application or other container.
Operators Reference provides a list of the operators AppleScript supports and the rules for using them, along with sections that provide additional detail for commonly used operators.
Control Statements Reference describes statements that control when and how other statements are executed. It covers standard conditional statements, as well as statements used in error handling and other operations.
Handler Reference shows the syntax for defining and calling handlers and describes other statements you use with handlers.
The following chapter describes an AppleScript-related feature of macOS:
Folder Actions Reference describes how you can write and attach script handlers to specific folders, such that the handlers are invoked when the folders are modified.
The following appendixes provide additional information about the AppleScript language and how to work with errors in scripts:
AppleScript Keywords lists the keywords of the AppleScript language, provides a brief description for each, and points to related information.
Error Numbers and Error Messages describes error numbers and error messages you may see in working with AppleScript scripts.
Working with Errors provides detailed examples of handling errors with try Statements and error Statements.
Double Angle Brackets describes when you are likely to see double angle brackets (or chevrons—
«»
) in scripts and how you can work with them.Libraries using Load Script describes how to save libraries of handlers and access them from other scripts.
Unsupported Terms lists terms that are no longer supported in AppleScript.
Conventions Used in This Guide
Glossary terms are shown in boldface where they are defined.
Important: This document sometimes uses the continuation character (¬) for sample statements that don't fit on one line on a document page. It also uses the continuation character in some syntax statements to identify an item that, if included, must appear on the same line as the previous item. The continuation character itself is not a required part of the syntax—it is merely a mechanism for including multiple lines in one statement.
The following conventions are used in syntax descriptions:
| Plain computer font indicates an element that you type exactly as shown. If there are special symbols (for example, |
placeholder | Italic text indicates a placeholder that you replace with an appropriate value. |
[optional] | Brackets indicate that the enclosed language element or elements are optional. |
(a group) | Parentheses group elements together. However, the parentheses shown in Handler Syntax (Positional Parameters) are part of the syntax. |
[optional].. | Three ellipsis points (..) after a group defined by brackets indicate that you can repeat the group of elements within brackets 0 or more times. |
a | b | c | Vertical bars separate elements in a group from which you must choose a single element. The elements are often grouped within parentheses or brackets. |
Filenames shown in scripts | Most filenames shown in examples in this document include extensions, such as To work with the examples on your computer, you may need to modify either that setting or the filenames. |
Script Editor Mac
See Also
These Apple documents provide additional information for working with AppleScript:
See Getting Started with AppleScript for a guided quick start, useful to both scripters and developers.
See AppleScript Overview, including the chapter Scripting with AppleScript, for a high-level overview of AppleScript and its related technologies.
See Getting Started With Scripting & Automation for information on the universe of scripting technologies available in macOS.
See AppleScript Terminology and Apple Event Codes for a list of many of the scripting terms defined by Apple.
Apple Script Sample
For additional information on working with the AppleScript language and creating scripts, see one of the comprehensive third-party documents available in bookstores and online.
Applescript Syntax
Copyright © 2016 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2016-01-25