Anyone using attached scripts?

A search revealed some tantalizing stuff, but no smoking gun…

I’m having trouble getting the following (simple) script to run as an attached script:


display dialog "Your favorite color is Grey"

It’s saved as a compiled script (data fork) ie .scpt file. When I click on the file it’s attached to in 3-pane view, or double-click on the document, I get no dialog with my message.

(Script seems to work as an attached script in Omnigraffle, FWIW)

Any help appreciated. Thanks! Charles

enclose your script with

on triggered(theRecord)
... your code
end triggered

Johannes

As an aside, when I first tried to get this to work, I noticed the following: suppose I write a script, call it “first.scpt”. In it I forget to write the “on triggered” part (clearly on purpose :slight_smile: ), so it doesn’t work as a triggered script. I try a couple of times to open the record to which it’s attached, nothing happens, I realise what is going on and add the “on triggered” part. Does it work now? No it doesn’t. But if I copy it) and attach the copied script (which is exactly the same), it works. Also if I restart DT. So DT apparently doesn’t reload the script if it’s changed.

How elegant! Anyway, just a heads up in case anybody else wastes his time working out what’s going on here.

Looks like the “Update Scripts Menu” selection in the DTPO Applescript menu will update everything without having to restart, or whatever…

I think this might be a side-effect of Applescript’s persistence once an instance is setup, and not some dorky aspect of DTPO. IF DTPO calls a script and Applescript sets up an instance around it, then you edit and recompile your script outside that instance, neither the Applescript instance nor DTPO knows about what you’ve done.

(Perhaps the DEVONthinkers could rename their menu selection to “Update Scripts,” though!)

Best, Charles

Aha, thanks! That greatly simplifies debugging my attachable scripts… I missed it because I don’t use the script menu (I use fastscripts), so I simply didn’t even see it…

Maybe. BBEdit, Mailsmith and other programs don’t do this, but then maybe there’s something about the attached scripts. At any rate, in normal use it’s not important, so I guess there wouldn’t be any reason to devote much time to it anyway.

It is a “dorky” aspect :open_mouth: DEVONthink is caching compiled scripts (especially triggered ones) as this speeds up their execution up to 10 times.

Very honest of you, as always…

As I don’t develop my scripts within DTPO, the speed-up is well worth the dorkiness factor.

Best, Charles

Indeed. It’s not so much trouble anyway. Maybe a mention in the manual would save someone else some time and frustration though :slight_smile:

I’ll add a paragraph to the documentation.

Thank you. Excellent service as always! :slight_smile:

I don’t have the “Update Scripts Menu” item in my DTPO scripts menu. Where can I get a copy of that? It’s tiresome having to repeatedly restart DTPO to have script changes take effect.

The latest releases automatically update the Scripts menu.

I have version 2.6.1 of DTPO but I don’t see the ‘Update Scripts’ item anywhere. Do I need to download and reinstall DTPO?

No. This menu item isn’t necessary anymore and has therefore been removed.