What’s new with automation in Yosemite

Apple introduced a great variety of new automation features and updates in Yosemite. I've written up a quick summary below with links to more detailed information.

AppleScript

AppleScript users have been requesting a built-in progress indicator for years. In Yosemite, Apple delivers. New AppleScript properties allow script developers to show and control a traditional progress bar in applets. In Script Editor, progress is shown at the bottom of the main window. For the Scripts menu, an "Automation" menu appears to show progress.

CombinedProgressFrom left to right, how the new progress indicator displays in applets, in Script Editor and the Automation menu (run from the Scripts menu)

For more information, see this short video from the new features page at macosxautomation.com.

AppleScript users have been able to access the power of Objective-C since the introduction of AppleScriptObjC five years ago. Originally, script developers had to learn to use Xcode to take advantage of this feature. In Mavericks, AppleScriptObjC can be used directly within regular scripts, but only through the use of separate script library files saved in a special format.

In Yosemite, separate libraries are no longer needed: AppleScriptObjC can be used directly in any script. Shane Stanley has released an update to his book, Everyday AppleScriptObjC, which covers how this works. As usual, Shane's book contains a lot of powerful sample scripts with detailed explanations. In the introduction he writes, "…in Yosemite, AppleScriptObjC is available everywhere, all the time. Truly Everyday AppleScriptObjC…Welcome to the modern world of AppleScript."

For power users of AppleScript, streamlined AppleScriptObjC access is the most significant new feature. But Yosemite also brings some improvements to AppleScript handler parameters, do shell script, as well as bug fixes. See the full release notes for more information.

Automator

Otto is getting some love in Yosemite as well. Workflows can now be saved as Dictation Commands, a new feature in Yosemite which appears to be an improvement over Speakable Items. A post by Christopher Breen at MacWorld covers how to turn on Dictation Commands and then start a workflow with a spoken command. (Red Sweater developer Daniel Jalkut discovered that Dictation Commands can also launch scripts.)

Sal Soghoian has released a set of new Automator Actions for Keynote. These are not included with Yosemite, but are available as a free download. The set includes many cool actions here, including Present Slideshow with Narration and Add Charts with Numbers Table Data.

CombinedNewActions2Two of the new Keynote Actions available for download.

Automator in Yosemite has a new Run JavaScript action allowing Automator users to call custom code written in JavaScript for Automation (see below for more info). This new action works in the same way as the existing Run AppleScript action.

New scripting support in iWork applications

Pages, Numbers and Keynote now all provide scriptable access to placeholder text objects, including a tag property for specifying a custom script tag to make it easier to change objects via scripting. Pages has added the ability to assign a tag for placeholder text in the user interface with the "Script Tag" field shown below.

PagesScriptTag3
The new Script Tag field in Pages makes it possible to assign custom tags to placeholder text for easy access via script.

To demonstrate these enhancements and provide some cool mail-merge/database publishing capabilities, see the new Pages Data Merge application. A demo movie provides more information.

As an automation developer, I'm always looking for better scripting support in Apple's own applications. Even with all this news, I find the new Script Tag field in Pages one of the most encouraging automation improvements in Yosemite. It is great when Apple adds any new objects to a scripting dictionary, but to add a user interface element specifically for working with scripting automation is huge. Let's hope we see even more of this in the future.

I've examined the scripting dictionaries of all three iWork applications, and beyond placeholder text and cosmetic improvements I see one new feature: Numbers has scripting support for the new Transpose feature.

JavaScript for Automation

There is now a new choice in writing scripts: JavaScript for Automation (JXA). Every application which supports Apple Events can also be scripted via JXA, which works via the scripting bridge.

Past attempts by Apple and third-party developers to bring Apple event support to sophisticated scripting languages such as Ruby and Python have not seen widespread adoption. But JXA has two big advantages over previous efforts: 1) JavaScript itself is hugely popular, with a great number of users developing for web browsers and other purposes. 2) Apple has integrated support for JXA directly into Script Editor.

You can use Script Editor to view dictionaries detailing an application's commands and objects. Like AppleScript, JXA can access Objective-C and Cocoa frameworks. The latter feature has led to some excitement at the prospect of using JavaScript in Script Editor to develop native Mac OS X applications with rich interface elements. While the idea of avoiding Xcode to develop applications certainly has appeal, I'm interested to follow what kind of success JXA developers have with writing Mac OS X apps without Xcode.

AppleScript users have had access to this feature for years, but other than the good work by Doug Adams at Doug's AppleScripts for Itunes, I have yet to see many AppleScript users adding interfaces this way. Instead, Automated Workflows and other developers have used AppleScriptObjC in Xcode to develop full-featured applications, perhaps in part due to the availability of Shane Stanley's excellent book on the subject, AppleScript Objective C Explored. I would advise JXA users wanting to develop apps to read this book. It has an excellent summary of the most important Xcode features, and much of the information about when classes (coming via the scripting bridge) need to be coerced is applicable to JXA as well.

Resources for learning more about JXA include a new video from Sal, Apple's release notes, and the JavaScript for Automation presentation at WWDC 2014.

Extensions in Yosemite

Automation in the AppleScript world has often been about scripting multiple applications to interact with each other. For years I've been using AppleScript to build scripts which grab data from apps like Word, Excel or FileMaker, generate sophisticated charts and other graphics in Illustrator, use InDesign to combine it all together in a sophisticated page layout, create PDFs and then distribute the final product via e-mail, FTP or other means. AppleScript can make this into a one step-process.

The ability of Mac applications to interact with each other faced some new challenges with recent OS X sandboxing restrictions. In Yosemite, we are seeing a new effort by Apple to standardize how applications can interact: Extensions. Alex Guyot with MacStories has an excellent article covering Extensions in Yosemite. (He also discusses JXA.)

Currently, Extensions allow for some UI-centered interactivity between applications. Automation developers may find immediate use for FinderSync Extensions and possibly other types of Extensions. Will Extensions in the future allow new ways to automate complex workflows? I hope so, but much remains to be seen about how developers will employ Extensions, and if Apple will open up the technology to scripting.

The future of automation

With so many improvements I've only see one errant assumption made by a few people: With JXA, Apple is finally replacing AppleScript, some say. Wrong.

There are many reasons why AppleScript will continue in the future, but a single point is enough to make it clear. Note all of the improvements to AppleScript in Yosemite described above. Why bother if AppleScript was being replaced? Case closed.

Perhaps the more interesting thing to watch is whether JXA will see widespread adoption. I can see many users developing solutions with JXA in Script Editor. And a few going on to develop full-fledged applications in Xcode. But AppleScript developers have many great tools for development that go beyond using a basic editor while avoiding the challenges of Xcode: Late Night Software's Script Debugger, Satimage's Smile, and ASObjC Explorer are all useful development environments with different features. I'm interested to see what third-party editing and development tools will emerge for JXA, but often a strong user base must emerge first.

Regardless, with new features available in Yosemite, the future of Mac OS X automation is strong, and AppleScript will remain a big part of that.

-Ray Robertson
ray@automatedwork.server323.com

Send Keynote 6.2 Presenter Notes to Evernote with AppleScript

A while back, I wrote an article for TUAW that demonstrated how to send presenter notes from a Keynote presentation to Evernote. This week, Apple released Keynote 6.2, and it contains some updated terminology. Here's an updated version of the script, which works with Keynote 6.2.

NOTE: You can download an example presentation containing presenter notes here.  You can download the completed AppleScript here.

Automation Changes in Mavericks – Official Tech Links

Lots of AppleScript and Automator changes were introduced with OS X 10.9 Mavericks. Here are links to official Apple technical resources that discuss some of them...

For a general overview of the automation changes in Mavericks, visit macosxautomation.com (not hosted by Apple Inc.).

2013 Penn State MacAdmins Conference > Automation Sessions

macadmins2013-logo-wide-940x298

I'm presenting two sessions at the Penn State MacAdmins conference next week:

  • Mac OS X Automation WorkshopThursday May 23, 2013 - 9:15am - 12:00pm - With AppleScript, Automator, and Services in Mac OS X, there’s more reason than ever before to begin automating time consuming and repetitive tasks. In this session, we’ll explore the potential of each of these automation technologies, discuss their benefits, and see how you can use them to boost your productivity and efficiency. Join us as we dive right in, begin creating Automator workflows, building services, and writing some simple AppleScripts. Take time to finally learn how to take advantage of these unique technologies in a relaxed “learn-by-doing” class.
  • Giving Your AppleScripts a Face LiftFriday May 24, 2013 10:45am - 12:00pm - You’ve been using AppleScript Editor on your Mac for years. You’ve developed dozens of useful scripts. It’s time to take those scripts to the next level by migrating them to AppleScriptObjC (Cocoa-AppleScript). In this session, we will expore the potential of this powerful technology. See first-hand how you can use Xcode to develop native Cocoa applications using AppleScript, complete with interfaces that allow you to capture data and provide detailed user feedback. In addition, learn how to add greater power to your AppleScript-based applications by integrating directly with Cocoa.

If you're attending, be sure and find me to say "Hi."

Macworld Article > 5 Automator workflows everyone should have

automator-icon_580-100036496-largeI meet a lot of people with Automator anxiety: they think using OS X’s built-in workflow-maker is a lot more complex than it really is. The truth is that Automator workflows are (a) pretty simple to assemble and (b) great for simple but repetitive tasks that you do all the time anyway.

To show you what I mean here are five workflows that I think pretty much every Mac user should have. They do things we all need to do: Wrap text in quotation marks, for example, or count the number of words in a selection of text. There might be other ways of doing the same things, but Automator is built into your Mac and you can implement them yourself for free in a couple of minutes.

[Read more on Macworld.com...]

TUAW Post > Adding Copy to Clipboard Rollovers in Contacts App via AppleScript

contacts_scriptApple's Contacts app includes a lot of great shortcuts for initiating different forms of communication. Just click an email address, phone number, or URL field label to display a list of available options. You can send an email, show a phone number in large type, or start a FaceTime call, for example. Curiously, one shortcut that's absent from most of these popups is one for copying the email address, phone number, URL, etc. to the clipboard. Mailing addresses are one exception, as they provide an option to copy a mailing label. But, other fields don't include this option. Sure, you could just select a phone number, email address, URL, etc., and press Command+C to copy it. But, what fun is that? It sure would be nice if there were just more handy copy to clipboard shortcuts instead. With the help of AppleScript, you can add your own. Here's how...

[Read more on TUAW...]

MacTech Article > Migrating AppleScript Studio Apps to AppleScriptObjC (Cocoa-AppleScript)

For years, AppleScript Studio provided scripters with a framework, through Xcode and Interface Builder, for implementing Cocoa interfaces in AppleScript-based apps. When it comes to AppleScript, end users are often accustomed to faceless apps that simply run when launched and quit when finished, with minimal feedback along the way. AppleScript Studio gave developers the power to implement feature-rich and user-friendly interfaces, which allowed users to configure script behavior, displayed progress during processing, and gave scripts the look and feel of virtually any other OS X app.

In August of 2009, Apple released Snow Leopard (OS X 10.6). At the same time, AppleScript Studio was deprecated and its official replacement, AppleScriptObjC, also known as Cocoa-AppleScript, was announced. AppleScriptObjC provides all of the benefits of AppleScript Studio, but with numerous additional benefits such as the ability to integrate scripts with any Cocoa framework in OS X.

Today, in Mountain Lion (OS X 10.8), Xcode no longer supports AppleScript Studio. Xcode includes project templates for creating AppleScriptObjC apps, but all references to AppleScript Studio are long gone. For long-time AppleScript Studio developers, this raises some core questions about supporting and migrating existing apps.

[Read the full article in MacTech magazine's March 2013 issue, available in print and in the MacTech iPad Newsstand app]

 

TUAW Post > Extract App Resource Icons with AppleScript

scriptWhether I'm preparing for a demo or writing an article, blog post, book, or technical documentation, I often find myself performing the same set of repetitive steps. I need to navigate into an app's packaged resources folder, find one or more icon files, occasionally convert them to PNG and scale them, and add them to my document, Keynote presentation, etc. Fortunately, this doesn't need to be a manual process each time, thanks to the following AppleScript.

[Read more on TUAW...]

TUAW Post > AppleScripting OmniFocus > Send Completed Task Report to Evernote 2

ofocus_scriptIn February, I provided instructions for using AppleScript to send completed task reports from OmniFocus to Evernote. The script was quite well received by readers, and I received numerous requests for enhancements. This post provides an updated version of the script, which includes a number of additions. The script now supports full project paths and additional task details including the context, estimated time, start date, modification date, completion date, and notes. This additional content is optional, and you can adjust the script to not display it if you wish.

[Read more on TUAW...]

TUAW Post > AppleScripting Email > Developing a Quoted Reply Service

outlook_autoA reader recently wrote to me with a problem. Apparently, Microsoft Outlook no longer contains the ability to create quote level chunks of text when replying to messages in plain text format. Why this functionality was removed, I can't say. But, with a little help from AppleScript and Automator, I was able to help the reader to add this functionality back via a Service. Better yet, the Service can be set up to work in any email client, or even systemwide in any app. Here's how you can do it...

[Read more on TUAW...]