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 the you’ll 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!< br/>-Justin.
How To Save And Run The Scripts
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.
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 two links underneath the source code box: One which automatically opens the script within your computer’s default AppleScript editor and one which, if you have a program called Snippets installed, allows you to save the script directly into its library.
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?
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.
What’s With The Snippets Link?
“Working with code” has been growing more mainstream in recent years: People are rolling up their sleeves and designing their own websites, using tools like AppleScript, and just taking a more D.I.Y. approach to technology than ever before. At some point, many of us realize that in fact, all this hacking around that we’ve been doing on our websites and home computers means we actually became “programmers” somewhere along the way!
Once you’ve crossed that threshold, you’ll realize that it’s really helpful to maintain your own collection of favorite scripts and snippets of code. There are a number of ways to keep track of it all and, lately, I’ve been using a program called Snippets to manage my code.1
Lucky Arts (the maker of Snippets) very graciously gave me a free license a few weeks ago so that I could review their app. Snippets is more expensive than other OS X-based Code Mangers but, even if I hadn’t received it for free, I would have bought it — and it’s the “code manager” app that I would currently recommend for Mac Users. Not only do I like the clean look of it, but they’ve built-in a couple of features which makes it a natural fit for the Veritrope.com Code Library:
Open In Snippets Links.
Lucky Arts has built-in something called “URI Handling” to Snippets but, to make that a little less jargony, it lets you create a “rich code snippet” which is completely contained inside a clickable link. After doing a little behind-the-scenes work with the plumbing in WordPress, Veritrope now automatically creates a Snippets link for every bit of code in the library. Just click it and it will be added to your local Snippets Library – complete with the full description from the Code Library and fully tagged for easy reference!
One of the main reasons that I opened the Code Library was to make the scripts I’ve been sharing here even more useful to you. I’m really trying to make it even easier for people to write their own AppleScripts which they can then tailor to be a perfect fit for their needs instead of just saying to my readers “Here’s a script I wrote… Good Luck!”.
For example — Writing an AppleScript which needs to tag items on the way into Evernote? I’ve got a few generic “Evernote Tagging Modules” that you can just drop into your script. Voila — problem solved!
Because it’s generic, I’ve put some “placeholder text” where certain labels would be — which is a fairly common practice. It’s easy enough to change manually, but Snippets makes it even easier! So long as I set up my “placeholder text” a certain way2, you can customize the generic AppleScript every time you use it in a new project just by selecting “Replace Placeholders” in Snippets. Just type in the new text and Snippets copies the new version directly to the Clipboard, where you can then paste it directly into your project. Doesn’t get much easier than that!
Hopefully, you’ll enjoy using the code library and these tools to build your own scripts and then share them in return with other Mac Users. 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!