Scripting ecto

A while ago, codeintensity (39) posted an interesting request on the ecto BB:

I'd like to request that ecto provide a way to insert text into blog entries by running a user defined/created/implemented script. The new Amazon support and the iTunes support got me thinking... I'd like to be able to write say a Ruby, Python, or AppleScript script that ecto would call, and from which it'd take text output and dump that into my blog entry. For example, maybe I want to insert the current weather where I am, or maybe the current status of some process or such on my machine.

Quite a few applications sport a Scripts menu, from which you can call AppleScript scripts. I never really cared much for it, but extending it to allow other scripting languages made it a lot more intriguing. The latest build of ecto for MacOSX has this new feature and it will be in the official version soon. Still in the works is the ability to call a script automatically before posting an entry, for example. In the meantime, feel free to play with it. I have included sample scripts in the archive, but first here's how it works. Scripts menu

ecto looks for scripts inside ~/Library/Application Support/ecto/scripts/ and loads them in its Scripts menu (see picture). Choose one of them from the menu and they will be called to work on your current draft. For example, select a word and choose “Google” from the Scripts menu. You will be directed to the browser where the Google search results are shown. “Posted with ecto” appends an attribution at the end of the draft (see below). These two scripts are AppleScript scripts. How about shell scripts? “Uptime Stats” gives us this info:

Processes: 74
Averages: 0.12 0.07 0.05
Uptime: 5 days 22:02

That's silly, of course, but it gives you the idea what is possible. Let's take it up a notch. “Validate HTML” is a Perl script which takes your selected text or the full contents of your draft and submits it to (51929) to check its validity. It lectured me on a missing 'p' element, which I obediently fixed.

My personal favorite is “Technorati”, which is also a Perl script, but it takes your text, extracts the URLs, finds the number of inbound links or Technorati Cosmos (30068) for them and inserts that back in the text (like in this entry).

Can you feel the power?

Here's the specifics if you want to write scripts:

The following script languages are allowed:

  • AppleScript
  • Bash
  • Perl
  • PHP
  • Python
  • Ruby

Filenames for the scripts must have the corresponding extensions:

  • scpt
  • sh
  • pl
  • php
  • py
  • rb

AppleScript scripts should use ecto's scripting dictionary to obtain an entry's (selected) text and whatever other information it needs. The other scripts are called with a parameter that points to a UTF8 encoded text file containing either the selected text or the entire contents of the front most draft's edit area. Any changes the script makes must be written back to the same file (UTF8 encoded). These scripts can also use STDOUT to channel HTML-formatted messages to ecto, which will then be displayed in an HTML window (see the validator for an example).

Users are encouraged to share their scripts. I will make a scripts page on this website to accomodate them.

[composed and posted with ecto (2104)]

Posted by Adriaan on December 22, 2004