Archives for October 2011

Developer Tip > Saving Mail Attachments via AppleScript Fixed in Lion 10.7.2

If you use AppleScripts that interact with Mail in Mac OS X (such as Mail to FileMaker Importer), you may have noticed that when Lion was introduced, the ability to save attachments through scripting no longer worked.  This issue affected AppleScripts, as well as Automator workflows (Apple's own Get Attachments from Mail Messages Automator action was broken too).  Well, I'm pleased to say that this issue has been resolved in Mac OS X 10.7.2.  AppleScripts can now save Mail attachments again.

If you'd like to learn more about AppleScripting Mail, check out my MacTech column... Introduction to Scripting Mail.

Attention Outlook Users: Saving attachments via AppleScript did not work in Outlook either until a recent Office update.  If your Outlook scripts are failing when attempting to save attachments, make sure you update your Office 2011 installation to the latest version.  While I don't have an article available at this time for scripting Outlook, you can learn about scripting Entourage in my MacTech column... Introduction to Scripting Microsoft Entourage.  The AppleScript terminology hasn't changed too much between Entourage and Outlook, so some of it may still apply.

Adobe Illustrator Automator Action Pack Updated to v1.07

The Adobe Illustrator Automator Action Pack (now version 1.07) has been updated to allow .ait documents to be opened.  The Ultimate Productivity Automator Action Pack (now version 3.19) has been updated to incorporate this change, as well.

More info or download a demo of the actions...

Mail to FileMaker Importer 2.2.1 Released

This update includes the following enhancements:

  • Re-instated attachment handling for Outlook 2011. This was previously disabled because saving attachments via AppleScript was broken in Outlook. Outlook 2011 (14.1.3) should fix this problem.
  • Updated to retrieve plain text for Outlook 2011 messages. Support for this was only recently added by Microsoft.

For more information on Mail to FileMaker Importer, or to download a trial, visit the M2FMI page...

P.S. Attachment saving for Apple Mail, which was broken in Lion, is now functional in Mac OS X 10.7.2.

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.

A moment in the life of Steve Jobs…

It was January 6th, 2004. Jen and I had just finished watching an enthusiastic Steve Jobs give the keynote address at Macworld Conference & Expo in San Francisco. We meandered about for a few minutes, trying to decide what to do next. Should we get lunch? Fight the crowds next door at the expo? Wander around the city? After a short debate, we decided to take on the expo, and then get lunch.

Due to our dilly-dallying, the doors were already opened when we arrived, and the crowd had been ushered into the expo. Great! No need for us to wait in line.

We entered near the Apple booth, which, as usual, was jam packed with attendees, eager to try out the latest and greatest from their favorite tech company. As we neared the booth, we noticed a small group of people entering behind us. As we turned, we were amazed to see Steve Jobs and John Mayer (who had joined Steve onstage to introduce GarageBand at the Keynote), along with a small group of reporters and Apple employees. Without much fanfare, they made their way to the Apple booth. We, of course, followed closely. After all, that's the direction we were heading anyway.

Steve, who rather comically wore an exhibitor badge, pointed out this and that to John Mayer, who nodded with interest. I snapped some photos. After a few moments, a woman walked up to Steve, glanced at his badge and said… "So, I'm having a problem with iPhoto. I can't get it to do this or that, and blah, blah, blah." Steve stopped in his tracks and listened to her question. Then, without hesitation, he gracefully snagged the arm of a nearby Apple booth worker and said "So and so will be glad to help you with that."

I don't know if anyone else heard this brief exchange, but it's one I will never forget it.  The woman was completely oblivious to the fact that he was one of the world's greatest technology visionaries.  Yet, he wasn't too important to stop and listen to her.  To that woman, he wasn't Steve Jobs.  He was a guy from Apple.  That he was, and I couldn't help smiling.

Steve Jobs smiles slightly, as he looks over the Apple exhibitor booth at Macworld 2004.
(Jony Ive, Senior Vice President of Industrial Design at Apple, is to Steve's right).

“I want to put a ding in the universe.” You did, Steve. Rest in peace.

Through the years, your success and vision has inspired me to be a better business owner, a better developer, and a better person. I feel fortunate to have been able to attend a number of your keynotes. Thank you.

-Ben

“Here’s to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes… the ones who see things differently — they’re not fond of rules… You can quote them, disagree with them, glorify or vilify them, but the only thing you can’t do is ignore them because they change things… they push the human race forward, and while some may see them as the crazy ones, we see genius, because the ones who are crazy enough to think that they can change the world, are the ones who do.”