Archives for May 2011

Accessing Properties of URLs with AppleScript

I recently stumbled upon the fact that a string can be coerced to a URL in AppleScript. This is cool because it allows you to access various properties of the URL, including the dotted decimal form of the URL's host.

"http://www.apple.com" as URL
--> {class:URL, scheme:http URL, path:"http://www.apple.com", host:{class:Internet address, DNS form:"www.apple.com", port:80, dotted decimal form:"23.0.29.15"}}

It should be noted that this isn't actually core AppleScript terminology. The "URL" class is terminology from the StandardAdditions scripting addition, which is included with Mac OS X.

Creating AppleScript Services in Mac OS X

Services are methods of inter-application communication in Mac OS X. They're ways for applications to share their features with other applications via the Application > Services menu, or through a Services contextual menu.

For example, open a TextEdit document and select some text. Next, choose TextEdit > Services > New Email with Selection. This is a Service provided by the Mail application.

I am often asked how to create AppleScript Services, i.e. scripts that you can run from the Services menu. There are a couple of ways to do this...

1) You can use Automator.

  • Launch Automator
  • Create a new Service workflow

  • Choose the type of content you want the script to process at the top of the workflow
  • Choose the application in which you want the service to be accessible
  • For text workflows, choose if you want the service to replace the selected text with the result of the workflow
  • Search for and insert the Run AppleScript action into the workflow
  • Enter your AppleScript code into the action. If you want the action to process the input, you'll need to write the code to do it. If you want to replace text, then you'll need to return text from the action as output

  • Save the workflow

You're done. You can now run the workflow from the services menu. Download a sample Service workflow that wraps selected text in quotes here.

2) The utility ThisService is a great tool for converting AppleScripts, Perl scripts, Python scripts, or Ruby scripts into Services.

Looking for some useful pre-existing Services to get you started? Visit macosxautomation.com to learn more about Services and download a TON of free Automator Service workflows.

Announcing Automated Workflows, LLC’s Website Redesign

I'm pleased to announce the redesign of the Automated Workflows, LLC website. The last time the site was redesigned was in 2007, so I felt it was about time to implement some changes. Key new features include:

  • Site-wide search
  • A blog, where I can post occasional productivity tips and other info
  • Consolidated products and services sections
  • A consolidated tips section, where you'll find dozens of my articles and videos
  • An integrated RSS feed with the ability to subscribe via FeedBurner
  • Links to my Twitter feed and LinkedIn page

I hope you find it useful.

-Ben

Ben Waldie
President
Automated Workflows, LLC