# Mac Automation Scripting Guide: Creating a Script

## Creating a Script

Generally, most scripts are written in Script Editor documents. Scripts can also be written in Xcode, but this is typically for scripts that require advanced user interfaces.

- Launch Script Editor in/Applications/Utilities/.
Launch Script Editor in/Applications/Utilities/.

- Press Command-N or select File > New.
Press Command-N or select File > New.

- If the script isnât configured for the correct language, choose the language in the navigation bar.TipIf you always use the same language, set it as the default language in the General pane of Script Editor preferences. SeeGeneral Preferences.
If the script isnât configured for the correct language, choose the language in the navigation bar.
If you always use the same language, set it as the default language in the General pane of Script Editor preferences. SeeGeneral Preferences.

- Write your script code in the editing area. Newly written code is uncompiled and formatted as new text.
Write your script code in the editing area. Newly written code is uncompiled and formatted as new text.

- Click the Compile button () to compile the script and check for syntax errors.If a syntax error occurs, an alert is displayed.If the script compiles, code formatting is applied at this time.
Click the Compile button () to compile the script and check for syntax errors.
If a syntax error occurs, an alert is displayed.
If the script compiles, code formatting is applied at this time.
You can change the formatting attributes, such as font and color, of uncompiled and compiled text in the Formatting pane of Script Editor preferences. SeeFormatting Preferences.

### Using an AppleScript Template

Script Editor includes a number of built-in templates for creating common types of AppleScripts, including droplets, Mail rule scripts, and Messages handler scripts.
Note
Script Editor does not include JavaScript templates at this time.

- Launch Script Editor in/Applications/Utilities/.
Launch Script Editor in/Applications/Utilities/.

- Choose File > New from Template.
Choose File > New from Template.

- Select a script template.A new Script Editor document window opens containing prewritten code and preconfigured settings. The following screenshot shows an example of a script created using a template.
Select a script template.
A new Script Editor document window opens containing prewritten code and preconfigured settings. The following screenshot shows an example of a script created using a template.

- Customize the script.
Customize the script.
Getting to Know Script Editor
Saving a Script
Copyright © 2018 Apple Inc. All rights reserved.Terms of Use|Privacy Policy|Updated: 2016-06-13