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."

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]

 

Peachpit Article > Building a Simple Image Processor with AppleScriptObjC (Cocoa-AppleScript)

My earlier article "Building a Basic AppleScriptObjC (Cocoa-AppleScript) Application with Xcode" explained how AppleScriptObjC and Xcode can be used to build robust interface-based applications for the Mac. While that article demonstrated this principle through the creation of a very simple Hello World application, the techniques provided can serve as the basis for building more advanced applications, for real-world scenarios. In this article, we'll build on those techniques to create a functional application that can perform some basic image manipulations, including flipping, rotating, and scaling a chosen image.

[Read more on the Peachpit.com...]

MacTech Article > Introduction to AppleScriptObjC (Cocoa-AppleScript)

AppleScriptObjC, also known as Cocoa-AppleScript, is a framework in OS X. It was initially released with OS X 10.6, and serves as the official replacement for AppleScript Studio, which Apple deprecated at the time. AppleScriptObjC is used by scripters to write rich, fully featured Cocoa apps in AppleScript. Think of AppleScriptObjC as the “Pro” version of AppleScript. For building simple scripts, AppleScript alone works great. For building advanced and complex scripts, perhaps with advanced interfaces, you want to think about moving to AppleScriptObjC.

If you’re a hardcore AppleScript developer or regular MacTech reader, then you’ve probably heard of AppleScriptObjC. You may have worked your way through a tutorial, and maybe even created a very simple app. If you haven’t used AppleScriptObjC yet, then you may have used Xcode in the past to develop AppleScript Studio apps. This month’s column starts with the basics. It provides a very introductory look at AppleScriptObjC. While we won’t build an actual app just yet, we’ll explore some of AppleScriptObjC’s core concepts and syntax.

[Read the full article in MacTech magazine's Fall 2012 Special issue, available in print and in the MacTech iPad Newsstand app]

Peachpit Article > Building a Basic AppleScriptObjC (Cocoa-AppleScript) Application with Xcode

In OS X Mountain Lion, AppleScript continues to be a powerhouse tool for controlling applications on the Mac. Whether you need to automate the creation of a few folders in the Finder, or generate a several-hundred-page product catalog in Adobe InDesign, AppleScript is waiting to lend a hand. Despite AppleScript's learning curve, Mac users everywhere are using it on a daily basis, and it saves time and money that might otherwise be wasted.

 AppleScripts aren't known for having slick interfaces. Perhaps most often, these scripts are written as simple applications, using the AppleScript Editor (found in/Applications/Utilities). When you double-click the application, it launches, performs some series of hidden tasks, and then quits. Developing script applications that work like this is quick and easy if you have the know-how, but if you're planning to distribute your script to other people, this format isn't always ideal. For one thing, aside from displaying simple dialog messages, you have no real way to let users know what your script is doing. Furthermore, unless users are AppleScript-savvy, there's no way for them to adjust the behavior of your script.

AppleScriptObjC (also called Cocoa-AppleScript) is an advanced method of developing AppleScript-based native Cocoa applications. With AppleScriptObjC, you can develop rich user interfaces and interact with them directly from your scripts. [Read more on the Peachpit.com...]

Sandboxing a Cocoa-AppleScript (AppleScriptObjC) Application

If you're a Mac developer, then you are probably aware that Apple will soon be requiring all applications submitted to the Mac App Store be sandboxed.  A sandboxed AppleScript-based application is kind of an oxymoron. Sandboxing denotes that an application will run in its own isolated environment, for security reasons.  Meaning that it doesn't have access to other applications on your Mac.  However, this goes against the nature of AppleScript, which is designed as an inter-application scripting language.  By writing AppleScripts, you can intertwine your various applications together to form complex workflows and automate time consuming things you would otherwise need to do manually.

So, how can you, an AppleScript developer, deal with sandboxing and get your app into the Mac App Store?  You can request temporary entitlements (translation: may not be supported in the future) for the apps and processes with which your app interacts.  Here are the general steps, which will vary depending on the actual function of your app:

1. Use Xcode to create your Cocoa-AppleScript app (AppleScriptObjC app)

2. In the Project Navigator, select your project

3. In the Project Editor, select your app's target

4. In the Summary tab, configure the following settings:

click to enlarge

- Enable Entitlements - Select this checkbox to turn entitlements on for your app

- App Sandbox - Select this checkbox to turn sandboxing on for your app

- File System - If you plan to use file/folder user interaction commands, such as "choose file", "choose folder", and "choose file name", then set this dropdown to "Read/Write Access".  Do the same if you plan to use commands such as "open for access" and "write".

5. In the Project Navigator, select the .entitlements file that should have been created automatically

6. Add an entry for "com.apple.security.temporary-exception.apple-events".  If you will have multiple entitlements, set this to be an array. Otherwise, set it to a string.  Add UTI entries for each application your app needs to target. For example, for the Finder, add "com.apple.finder". For iTunes, add "com.apple.itunes". If you don't add a temporary Apple Events entitlement and the necessary UTIs, then your app will produce errors when attempting to target external applications.

click to enlarge

7. If your app will write to a directory in the user's home folder, add an entry for "com.apple.security.temporary-exception.files.home-relative-path.read-write".  Set this to be an array, and add paths to any folders you will write to, beginning each with a slash. I.e. /Desktop/ represents the user's Desktop.

That should do it.  Build and run your project, and check Xcode's debug console for problems.

Download an example of a sandboxed Cocoa-AppleScript Xcode project here.

Official documentation for sandboxing an app can be found on Apple's developer website.

Note that sandboxing doesn't affect strictly AppleScript applications.  Other applications could potentially be affected, as well, including Automator* and numerous popular third-party applications.  Well, to be fair, these applications could still work.  They just couldn't be submitted to the Mac App Store once Apple's sandboxing requirement goes into effect, at least not without employing temporary entitlements.

For more on the growing controversy regarding sandboxing and inter-application communication, check out:

* In theory, Automator actions contained within a sandboxed application should not need to be sandboxed themselves.  This is because they would technically fall under the scope of the application that loads and runs them - in this case - Automator.  So, their capabilities should be governed by Automator's sandbox, which, due to the nature of Automator, should allow them to run unimpeded.

Blurb Tally 1.1.2 AppleScript-Cocoa (AppleScriptObjC) app sandboxed and approved for Mac App Store.

Blurb Tally 1.1.2 has been sandboxed and released in the Mac App Store.  This was mainly done to ensure that sandboxed AppleScriptObjC apps would be accepted in the Mac App Store.  Apparently, they will.