Proxi can do that too!
I originally posted this on the Proxi Blog
I ran across a post on Daring Fireball today which described using a perl script along with ThisService to search Google for selected text and replace that text with a link to first result returned by Google. Very handy, but I wanted to achieve the same functionality using Proxi.
Proxi supports shell script execution, but only as extra values (for now) so that makes it a little trickier. If you don’t care how much trickier, you can skip the rest of this and simply grab the blueprint.
We have to first break down the blueprint into several stages:
- Put the selected text on the clipboard.
- Construct a script using the text we’ve selected. Display the query.
- Execute the script, place the results in the clipboard, paste and display the results.
More specifically:
Stage 0 – A Control-Shift-L Hotkey Monitor trigger starts the ball rolling. It executes two tasks, a Command-C Key Press to initiate a copy, then an AppleScript which waits a short while to allow the clipboard to export after which it asks Proxi to handle an AppleScript trigger named “query stage 1”.
Stage 1 – Is an AppleScript trigger continues the process. This trigger will fire when Proxi is triggered via AppleScript with the correct name. In this case the name it’s looking for is “query stage 1”. The trigger places the contents of the clipboard into a value named “Clipboard” and executes a Screen Message task to display the search term. Next it write our a perl script using the clipboard contents and the Write to File task. Finally, it kicks off the last stage with another AppleScript task named “query stage 2”.
Stage 2 – An AppleScript trigger which matches “query stage 2”. When fired, it executes the perl script we made in Stage 1 and places the results in an extra value named “ScriptResults”. ScriptResults is displayed in a Screen Message task and loaded onto the clipboard using a Load Clipboard task. Finally, Command-V (paste) is simulated to insert the results in place of the selected text.
This is a great little exercise to demonstrate how to construct complex triggers using Proxi. It also demonstrates some of the shortcomings of Proxi that I’d like to address in future revisions. The ability to execute a script as a task and also modify values during task execution would eliminate the need to break this down into three separate triggers. In the meantime, I hope this helped.
The Proxi wiki has a download link as well as additional information on the Insert Link Blueprint.