TweetFollow Us on Twitter

A Fresh Perspective On AppleScript: An Interview with an AppleScript Newbie

Volume Number: 24 (2008)
Issue Number: 09
Column Tag: AppleScript

A Fresh Perspective On AppleScript: An Interview with an AppleScript Newbie

AppleScript insights and thoughts from a newcomer to the language

by Ryan Wilcox

Why This Article

AppleScript: the oft-maligned scripting language from Apple has been included on every Mac since System 7.1. AppleScript's key weapon might just be its English-like syntax, making AppleScripts very readable by just about anyone.

Sometimes talking to a newcomer to a technology or language reveals things we, in our familiarity, have forgotten. This article is meant to look at AppleScript, by interviewing a newcomer to the language.

About The Interviewee

Kevin Hartman majored in Studio Art with a Graphic Design concentration, where he used Macs heavily in his education. After college he got a job at a college in Rochester, NY, where he's been a Mac technology support specialist/system admin since 2007. Kevin is a switcher, having spent most of his time on Windows PCs. Along with AppleScript, Kevin dabbles in HTML/CSS, Flash/ActionScript, and a bit of Python.

The Interview

Tell us about your experiences writing your first script. How did you begin using AppleScript?

It was actually suggested by a coworker. He dabbled in it himself in the past, and when we needed a network drive [mounted automatically] he suggested we look into AppleScript to accomplish the task. So I started asking around and browsing forums and pulled together what I had found. Of course, it didn't work the first 20 times or so (maybe a little exaggeration), but I was able to tweak it and make it work for what we needed.

Tell me about that script

The script's purpose is to mount student's Active Directory home folders when they log into a lab computer. The script mounts the network volume using "whoami" to identify the specific user's folder. Worked great, except when the volume was already mounted, it couldn't get the folder to come up because the mount part would get an error "already mounted". So then I did some more browsing, figured out how to put in a conditional to detect if the volume was already mounted, then act accordingly.

We changed it slightly soon after. We thought, "what if the user closes out that folder? Then they would have to manually browse to it again." So, I wrote a second script, which I will refer to as the alias script. The alias script runs on login, again with a conditional, and creates an alias to the volume mount script on the desktop. That way, the user just double clicks the icon labeled "Open Your Network Drive" or something to that effect, and it mounts the volume and opens the folder... or just opens the folder if the volume is already mounted.

What do you think about AppleScript as a language?

Thus far, I think AS as a language/tool has been very useful and relatively easy to pick up. The English-style writing of the language makes it easily accessible for someone who, like me, has done little more than dabble in code in the past.

So how did you go about picking it up then? Do you have any resources for the total newbie?

The first script, the Active Directory home folder script, was done through forum searches and personal contacts to get it working. After that, I picked up a couple books. Beginning AppleScript by Kochan (from Wrox), and AppleScript The Definitive Guide by Neuburg (from O'Reilly). After that, I mostly used the Guide for reference, and used the dictionary viewer.

What I like about AppleScript is how easily approachable it is. For the most part, the phrasing for the code makes sense. As an example: tell application "Finder" to ... is like writing a sentence, and little or no strange characters and such... no $ # ! ; : to remember what each do.

You're right some experts write AS with lots of symbols, for complex things, but for the most part it's straightforward English.

When I look at AS examples, it makes sense... when I look at other code examples it just looks like a printer error that threw up on my screen.

Have you ever run up against something weird or confusing in AppleScript?

Yes: sometimes in AS you start using shell commands, and that can get confusing. I'm not exactly sure how it works, but I noticed that folder path was completely different, and knowing which one to use in which case...

Mac HD:Users:... vs /Users/... ?

Yeah.

Usually the former goes with alias "" and the latter goes with POSIX file "".

Anyway, beyond its English-like syntax, is there anything else you really like about AppleScript?

I really like the fact that AppleScript is integrated into the OS, making it easy to manipulate other programs with it.

True: you can talk to the Finder, then go over there and talk to another program, then...

Exactly.

Where do you think AppleScript could improve?

I think one thing that would help a lot would be examples of code within the dictionary, rather than just telling you what it does.

Another thing that would help for us beginners is some kind of list of what AppleScript uses for object names such as: drawer; text field, window, and panel, and where each one is used.

In my opinion, it's all well and good to have each of those in a dictionary or whatever, but if you don't know what you are looking for to begin with... Basically, knowing a drawer is "drawer" or a Label is "text field"... or a Custom View (in interface builder) is "view" in AppleScript... maybe what I'm looking for is a list of each class, like window, drawer, text field, view, etc.

The verbs in the dictionary viewer are grouped with the nouns... maybe an easier way to see all the nouns, no matter what "suite" they are in?

Yes. For example, there was one feature that was pretty nice in ActionScript 2.0 that gave you "hints" and auto-completion options while typing the code. If I started typing "on" it would pop up a window beneath the cursor, without interrupting, with all commands that follow "on". So it would start listing "(release)" "(releaseOutside)" etc etc. and you could either just keep typing, use the mouse to select one, or if you just hit return, it would use the top option. The list would be refined as you typed. Then, once you start typing a command, such as "goto", it would pop up anything with "goto" in it... so would pick "gotoAndStop", THEN it popped up a little yellow "note" with context for the gotoAndStop like so "gotoAndStop (frame # or name)". This feature was rather handy for the beginner, 'cause the hints and contexts were given to you on the spot

XCode has Code Sense, which works for AppleScript too, but it's not that involved. Script Editor has a Script Assistant feature which is better, which might help if you're writing just scripts... Have you tried out any of the third party AppleScript tools, like Script Debugger or Smile or Facespan?

Not really. I was using Lingon at one point, but that was mostly just a tool to make a script run on login and work with Launchd.

What are your suggestions for new users?

I would say pick up some books, check your online resources and try to find someone you can chat with for those times you get stuck.

Acknowledgements and Resources

Well thank you for your time today, Kevin. For you and other people trying to learn AppleScript, let me suggest some resources to help you out with learning AppleScript.

First, MacTech's archives include almost 3 dozen articles from Benjamin Waldie, from http://automatedworkflows.com. His articles are outstanding, and run the gamut from beginner articles to scripting specific applications. MacTech's archives have other AppleScript articles too, ranging from recent to ancient history. All of these articles can be found on-line at http://www.mactech.com/articles

Secondly, and already mentioned in the interview, there are several really good AppleScript books out there: Beginning AppleScript by Kochan (from Wrox), and AppleScript The Definitive Guide by Neuburg (from O'Reilly) are the two we mentioned, but Apple Training Series: AppleScript 1-2-3, written by two essential members of the AppleScript community, is certainly one to watch out for (coming July 27, 2008). There are also two books at http://www.spiderworks.com: Danny Goodman's AppleScript Handbook OS X Edition; and AppleScripting the Finder (by Benjamin Waldie). Spiderworks also has several other books on AppleScript and Automator.

Ryan Wilcox is a long time language dabbler, including AppleScript, which he's been using since Mac OS 8. His company, Wilcox Development Solutions (http://www.wilcoxd.com) has long used AppleScript for workflow optimization. He can be reached at rwilcox@wilcoxd.com.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Duet 2.0.5.1 - Use your iPad as an exter...
Duet is the first app that allows you to use your iDevice as an extra display for your Mac using the Lightning or 30-pin cable. Note: This app requires a $9.99 iOS companion app. Version 2.0.5.1:... Read more
Monosnap 3.5.6 - Versatile screenshot ut...
Monosnap lets you capture screenshots, share files, and record video and .gifs! Features Capture Capture full screen, just part of the screen, or a selected window Make your crop area pixel... Read more
Sketch 53.2 - Design app for UX/UI for i...
Sketch is an innovative and fresh look at vector drawing. Its intentionally minimalist design is based upon a drawing space of unlimited size and layers, free of palettes, panels, menus, windows, and... Read more
Adobe Acrobat Reader 19.010.20098 - View...
Adobe Acrobat Reader allows users to view PDF documents. You may not know what a PDF file is, but you've probably come across one at some point. PDF files are used by companies and even the IRS to... Read more
iClock 4.6.7 - Customizable menu bar clo...
iClock replaces the old Apple's default menu bar clock with more features, customization and increases your productivity. Features: Have your Apple or Google calendar instantly available from the... Read more
VueScan 9.6.32 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Dropbox 67.4.83 - Cloud backup and synch...
Dropbox is an application that creates a special Finder folder that automatically syncs online and between your computers. It allows you to both backup files and keeps them up-to-date between systems... Read more
Opera 58.0.3135.68 - High-performance We...
Opera is a fast and secure browser trusted by millions of users. With the intuitive interface, Speed Dial and visual bookmarks for organizing favorite sites, news feature with fresh, relevant content... Read more
Microsoft Office 2016 16.22 - Popular pr...
Microsoft Office 2016 - Unmistakably Office, designed for Mac. The new versions of Word, Excel, PowerPoint, Outlook, and OneNote provide the best of both worlds for Mac users - the familiar Office... Read more
Slack 3.3.7 - Collaborative communicatio...
Slack is a collaborative communication app that simplifies real-time messaging, archiving, and search for modern working teams. Version 3.3.7: What’s New  From today, you'll notice a shiny new app... Read more

Latest Forum Discussions

See All

The best games for iPhone and iPad that...
Well, once again we've reached Thursday, which means it's time to have a look at the awesome games that have popped up on the App Store over the past seven days. We've got horror, we've got vampires, and we've got at least one game we still don't... | Read more »
The AAF app could be the only fantasy fo...
Fantasy football is massive, which is something the AAF understands. It's a new American Football league that's two weeks into its first season. It's designed to serve a number of different masters - for one thing it's positioned itself as a second... | Read more »
Everything you need to know to win in Ja...
Jaws.io is one of those games that just shouldn't be as much fun as it is. But it is as much fun as it is, so there you go. It's a game all about eating things, shooting a giant shark, and trying to score as many points as possible. And if there's... | Read more »
Everything you need to know to win in Kn...
Knights of the Card Table is a really clever, solitaire dungeon crawler that's not just crammed to the gills with monsters to fight and loot to find, it's also got one of the biggest hearts of any game we've seen on the App Store. We definitely... | Read more »
A quick beginner’s guide to Final Blade
Final Blade was developed by newcomer SkyPeople studio, with help from localisation guru Glohow. After two years exclusively in the hands of South Korean and Chinese players, the game is now celebrating its global launch. Hurrah! But if you’re a... | Read more »
The best games for iPhone and iPad that...
How is it already Thursday again? My oh my, doesn't time fly when you're playing the very best mobile games out there? We certainly hope it does, because we've gone ahead and written a list of what we think are the top 5 best games for iPhone and... | Read more »
Three games for iPad and iPhone to keep...
On Monday we told you that Apex Legends is, all being well, eventually going to end up on the App Store. That means you'll be able to play one of the best new battle royale shooters in months in the palm of your hand. However, it hasn't happened... | Read more »
Why you should be excited about Apex Leg...
You've no doubt heard of Apex Legends by now. It's a new take on the battle royale genre developed by Respawn, and published by EA. It went live on EA Origin, PS4, and Xbox One last week, and it's already been generating a lot of buzz around the... | Read more »
Epic fantasy RPG Final Blade celebrates...
Now is a great time for RPG fans the world over as Final Blade has, well, finally got its global release for iOS and Android. The grand-scale RPG developed by Skypeople Inc in association with Glowhow, the has been quite the hit over in Taiwan and... | Read more »
Airheart launches on Nintendo Switch, de...
You’d be forgiven for thinking a game about harpooning fish and fighting pirates would be set on the high seas. But the action in Airheart is entirely airborne. Following up on its PC and Playstation release last year, this award-winning game has... | Read more »

Price Scanner via MacPrices.net

Get the 21″ 3.4GHz 4K Apple iMac for $1399 to...
Abt Electronics has the 21″ 3.4GHz 4K iMac on sale today for $1399.99 including free shipping. Their price is $100 off MSRP, and it’s the lowest price available for this model: – 21″ 3.4GHz 4K iMac... Read more
iMac sale! Get a new 27″ Apple iMac for $200...
B&H Photo has new 27″ Apple iMacs on sale for $200 off MSRP, starting at $1599. These are the same models offered by Apple in their retail and online stores. Shipping is free: – 27″ 3.8GHz 5K... Read more
Apple restocks Certified Refurbished 4K Apple...
Apple has restocked Certified Refurbished 32GB and 64GB 4K Apple TVs for $30 off the cost of new models. Apple’s standard one-year warranty is included with each model, and shipping is free: – 32GB... Read more
Save $50-$62 on a new Apple Mac mini at Abt E...
Abt Electronics has the new 2018 4-Core and 6-Core Mac minis on sale for $50-$62 off standard MSRP, with prices starting at $749. Shipping is free: – 3.6GHz Quad-Core mini: $749 $50 off MSRP – 3.... Read more
13″ Dual-Core 2.3GHz non-Touch Bar MacBook Pr...
Apple resellers B&H Photo and Amazon are both offering sale prices on new 13″ Dual-Core 2.3GHz non-Touch Bar MacBook Pros, ranging up to $150 off MSRP, with prices starting at $1199. Shipping is... Read more
Could These Be The Products That Apple Will B...
NEWS: 02.20.19- Apple, Inc. is widely expected to be releasing a number of new products in the pipeline this year but just what exactly will those items be and who is the source of all of that... Read more
B&H has 42mm Apple Watch Series 3 GPS + C...
B&H Photo is discounting 42mm Apple Watch Series 3 GPS + Cellular models by $60. Shipping is free: – 42mm Apple Watch Series 3 GPS + Cellular: $349 $60 off MSRP Their price is the lowest... Read more
Get $50 off an iPhone 8 at Verizon with this...
Looking for a discount on a new Apple iPhone 8 at Verizon? Use coupon code VZWDEAL to save $50 on a new iPhone 8 through February 28, 2019. Excludes upgrades & online only. Read more
Jet offers the 12″ 1.2GHz Silver Apple MacBoo...
Jet.com has current-generation 2017 Apple 12″ 1.2GHz Silver MacBooks on sale today for $290 off Apple’s price. Shipping is free on all orders over $35 at Jet: – 12″ 1.2GHz Silver MacBook: $1009.65 $... Read more
New 11″ Apple iPad Pros on sale for $50-$100...
B&H Photo has the new 2018 Apple 11″ iPad Pros in stock today and on sale for up to $100 off MSRP. Shipping is free: – 11″ 64GB WiFi iPad Pro: $749 $50 off – 11″ 256GB WiFi iPad Pro: $900 $50 off... Read more

Jobs Board

Temporary Associate - *Apple* Blossom Mall...
Temporary Associate - Apple Blossom Mall Location:Winchester, VA, United States- Apple Blossom Mall 1850 Apple Blossom Dr Job ID:1041589 Date:Tomorrow Job Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States- Apple Blossom Mall 1850 Apple Blossom Dr Job ID:1044618 Date:February 18, Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States- Apple Blossom Mall 1850 Apple Blossom Dr Job ID:1042611 Date:Tomorrow Job Description Read more
Sephora Product Consultant - *Apple* Blosso...
Sephora Product Consultant - Apple Blossom Mall Location:Winchester, VA, United States- Apple Blossom Mall 1850 Apple Blossom Dr Job ID:1056553 Date:February Read more
Omni-Channel Associate - *Apple* Blossom Ma...
Omni-Channel Associate - Apple Blossom Mall Location:Winchester, VA, United States- Apple Blossom Mall 1850 Apple Blossom Dr Job ID:1074107 Date:February 18, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.