Make new AppleScripts automatically

If you're a regular reader of this blog or the OS X Hints site on which it's based, you know we regularly post AppleScripts that do one useful thing or another. You may also be tired of manually copying-and-pasting those scripts from your browser to AppleScript editor or Automator. Hints reader Maxikubik felt that way, so he created an Automator service to do it for him.

But before you go to the trouble of implementing his script, note that you may already have a similar service installed: Go to the Keyboard pane in System Preferences, open the Keyboard Shortcuts tab, and look for a service called Make New AppleScript in the Development section. If it's there, it'll do much the same thing as Maxikubik's script: Select a script, then choose the service from the contextual menu. A new AppleScript window will open, with the selected script pasted into it. That service is disabled by default so you'll need to turn it on by clicking on its checkbox.

If, for some reason, that service isn't there, here's how to build your own: Open Automator, choose new Service from the list of templates, and configure it to receive text in any application. Next, add the Run AppleScript action (from the Utilities section on the left) and replace the script body with:

on run {input, parameters}
	
    tell application "AppleScript Editor"
        activate
        if (count documents) > 0 and contents of document 1 is "" then
            set contents of document 1 to (input as string)
        else
            make new document with properties {contents:(input as string)}
        end if
    end tell
	
    return input
end run

Select File -> Save As and give it a name (such as New AppleScript document with selection). That done, next time you see a script you want to save, highlight the code, right-click on it, then select this service from the contextual menu. (If it doesn't show up there, open the Keyboard Shortcuts tab again, and make sure your service is listed in the Text section; if it is, but isn't checked, check it.)

-----

One other housekeeping note: The winners of our February Hint of the Month contest have been announced. As you might recall, every month we choose the four best tips that have appeared on OS X Hints: two tips of general interest and two on a specific topic; in February, that topic was iLife '11. The people who submit those four tips then get $250 each. So, for February, the winners were:

Congratulations to all four winners. And come on over to the OS X Hints site and check out the submissions for this month's contest. The special topic: Web browsers.

Subscribe to the MacWeek Newsletter

Comments