Fri 18 Sep 2009
I have always liked the idea of the Services menu, but found it frustratingly crowded and not often helpful. And I always thought Automator had real potential, but I never really found a place for it in my day-to-day work. With the improvements to the Services menu in Snow Leopard, the combination of these features is wonderfully useful.
SlickEdit’s Slick-C macro language should be no stranger to our users, but many folks aren’t aware that macros can be called when SlickEdit is started. In this tutorial, I’ll demonstrate how to use Automator to create a simple text service for SlickEdit, using this macro call facility.
First, launch the Automator application and create a new service using the Service template. At the top of the new workflow, it should say Service receives selected text in any application. Make sure Replaces selected text is not checked.
From the library’s actions panel, select the Text > New Text File action, and drag it into the workflow as the first item. Pick a name and location for the temporary file to be saved, and make sure Replace existing files is checked, or else you’ll receive an Automator error the second time you use the service. Select the Encoding to be (UTF-8).
From the library’s action panel, select the Utilities > Run Shell Script action, and drag it into workflow as the second item. The shell should be set to the default of /bin/bash. Change the right-hand drop-down to read Pass input as arguments.
Delete any existing text in the shell script editor. Add the following text as the first line.
Switch to Finder, and navigate to the Applications directory. Highlight your SlickEdit application, and Control-Click the application, and select Show Package Contents from the context menu. Drill down to the Contents/slickedit/bin, highlight the vs executable, and drag this into the shell script editor. This will insert the full path to the executable in the script editor. Make sure it’s on a new line after the export line you just typed.
Append the following right after vs, making sure the command is all one line.
-#new-file "-#get $1"&
The full script should look like the following:
export VSLICKXNOPLUSNEWMSG="1" /Applications/SlickEditV1402.app/Contents/slickedit/bin/vs -#new-file "-#get $1"&
Don’t forget the ampersand at the end of the second line. Save the service, (⌘+S), and give it the name “New SlickEdit File”.
Switch to another application, like Safari or TextEdit, highlight some text, and pull down the application’s services menu. Your new service should now be available in the menu in the Text category.
The SlickEdit “magic” is done with the -# arguments. These specify macros to be called when SlickEdit in invoked. Any SlickEdit macro command (defined with the _command keyword in Slick-C) can be called. Surround the entire -# argument with quotes if the Slick-C command takes any parameters, like the get macro in this example.
You can create a similar service that will insert the text into the currently active document by simply removing the -#new-file argument.
By default, service workflows are saved under $HOME/Library/Services. You can remove the service by removing this file.
To rename a Service, select the workflow file under $HOME/Library/Services, Control-Click to bring up the context menu, and select Show Package Contents. Look for the Contents/Info.plist file, and open it in the Property List Editor application. Change the value of the Services/Item/Menu/Menu item title entry. You do not need to rename the workflow file itself.