Q: DEVONthink Execute Perl Script applescript

I would love a quick run-through on how to actually use DEVONthink Pro’s bundled Applescript for executing Perl scripts. I’m a novice to both Perl and Applescript, but am trying to learn.

Looking at part of the script (edited down a bit):

set this_source to text of think window 1 as string
try
	if length of this_source > 0 then
		set this_path to quoted form of "/tmp/DEVONthink Pro/_temp_.pl"
		do shell script "echo " & quoted form of this_source & ">" & this_path
		do shell script "perl " & this_path
	end if

It looks like I should have a text document in DT Pro that’s a valid Perl script, select Execute Perl Script off the Script menu, and then the script should execute after being copied into a tmp directory temp.pl file, right?

Where does any printed output go?

Could you give a simple “hello world” example?

Is it possible to send it another DEVONthink text file, or text clipboard contents, to the Perl script as an input?

I tossed in a simple:

#!/usr/bin/perl
use strict;
use warnings;
print "Hello world\n";
exit;

…and tried to execute it, but nothing happened.

Thanks,

Joe

Well, I might as well reply to myself, in case anyone else wants to play around with this in the future. I could NOT include the #! at the beginning, and I needed to write the output to a text file and then execute a shell command to open the output text with TextEdit. The following worked:

my $outputfilename = '/Users/joe/Desktop/output.txt';

open OUTPUTFILE, ">$outputfilename";
print OUTPUTFILE "Hello, world.\n";
close (OUTPUTFILE);
`open $outputfilename`; # shell command

exit;

Now, if anyone has got any ideas about how to send information from a text document inside DEVONthink to the Perl script, and then have the output written back to a document in DEVONthink, that would be useful to do more sophisticated text processing from within DEVONthink. I suspect Applescripts would be a better way to go, because you could send the DT application commands, but I know even less about Applescript than I do about Perl.

Joe