The Basics: How To Use AppleScripts From

I thought I’d create a quick post for people who are brand-new to AppleScript or who are just checking out the new Code Library for the first time: As the title suggests, it isn’t as much about “How To Use AppleScript” as it is about how to use the AppleScripts that you find here!If you’re interested in learning more about AppleScript, be sure to check out the AppleScript and Automator Resources Page. It’s filled with links to books, videos, tools, and websites that’ll help you get started!-Justin.

How To Save And Run The Scripts

Open In Script Editor
Depending on the type of script or project, I’ll either provide you a direct download link or a link which opens the script in your default AppleScript editor.

Script Editor Button

The “Open in Script Editor” and “Submit Bug Report” buttons are on the right side of each progect page.

Let’s use the Set the Location of Evernote Items With Google Earth script as an example. You can, of course, just cut-and-paste the source code from the “Code” box directly into your AppleScript Editor. For your added convenience, however, you’ll find some helpful links to the right of the source code box: “Open the Code in Your Script Editor” automatically opens the script within your computer’s default AppleScript editor, saving you the cut-and-paste. Have a problem saving the script or getting it to work properly? Use the “Submit A Bug Report” link to let me know!

Purple Text Means It’s *Almost* Ready! (Click To Enlarge)

For most people, clicking the “Open in Script Editor” link opens the script in a program called “AppleScript Editor” — an application that comes with every Mac. It’ll look something like the source code you saw in the box above the link, but its text will be purple. Purple text in AppleScript Editor means that the program hasn’t been “compiled” yet or, put another way, it means that AppleScript Editor hasn’t checked it out to verify that there aren’t any massive mistakes in our source code.

To have AppleScript Editor compile the code, you can either press the “Compile” button which checks the code without running it or you can press the “Run” button which will check it and then run it.

Saving the script is much like saving anything else on the Mac: The File Menu has “Save” just like many other applications you’ve used before. Select it and you’ll be able to select where your script gets saved and what it’s called. Personally, I like to save my scripts in the /Library/Scripts folder so that they’re available for every user account on my computer.

Save As Script or Application?

Save Box

A Standard Save Box — With One Caveat…

The only thing that you really need to know about the AppleScript Editor’s Save Dialog is that it gives you a choice to save your script in a few different formats. For our purposes here, you’ll save them as either a Script or as an Application. The difference between the two is pretty simple: When you open an AppleScript file saved in Script format, it opens the AppleScript Editor and you see the source code. This is the way you’ll want to save it if you intend to edit the code a bit and not just run it as written.

If you open an AppleScript file saved in Application format, opening the script runs it without opening it up in the Editor — or in other words, just like any other Application on your Mac. This is perfect for scripts that don’t need additional edits and which you’d like to run from a keyboard shortcut. ((Note–Some scripts require modification to run as Applications)

Wrap Up

Hopefully, you’ll enjoy using the code library and these tools to build your own scripts. I’ve tried to make it as easy as possible for you to roll up your sleeves and get started but, if there’s something you think I’ve missed here, please let me know!

5 Responses to “The Basics: How To Use AppleScripts From”

  1. Kolz April 3, 2011 at 3:42 pm #

    Nice work ! Works like a charm. Question. Where do some of those other folks additions go in your script. Newbie !

    • Justin Lancy April 3, 2011 at 4:24 pm #

      Depends on the script! 😉

      Just leave a comment on each script’s page to ask for help and we’ll get you sorted out!

  2. kolz April 3, 2011 at 4:34 pm #

    Different question since i got the right topic.

    for evernote scripts, is their a folder you need to drop the script in like MS Outlook 2011?

    Newbs i am

    • Justin Lancy April 7, 2011 at 12:38 pm #

      Not required but, sometimes, an app has its own script menu and it’s more convenient to use from there.

      For example, if you’d like to see it appear in Outlook’s script menu, you can copy a script to:
      (Your User Directory)/Documents/Microsoft User Data/Outlook Script Menu items