Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Tagging with Applescript
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1241444250

Message started by Charles Turner on May 4th, 2009, 9:37am

Title: Tagging with Applescript
Post by Charles Turner on May 4th, 2009, 9:37am

Hi all-

Here's a little TB beginner contribution. I've been working with a large quantity of notes taken from OCR'ed PDFs, and the citations are in the notes, but badly formatted. I wanted to automate the process of assigning citation info to user attributes in TB, and this is what I came up with.

First an example Applescript:

activate application "Tinderbox"
tell application "System Events"
     tell process "Tinderbox"
           keystroke "x" using {command down}
           delay 0.1  -- wait for the clipboard
           set theSelection to the clipboard
           set theSelection to "<au>" & theSelection & "</au>"
           set the clipboard to theSelection
           keystroke "v" using {command down}
     end tell
end tell

(You'll have to have GUI scripting turned on to use this script.) What the script expects is some selected text in a TB note, in this case an author name:

J. Fred Muggs

Running the script will cut the selection to the clipboard, tag what's there and paste it back into the TB note like so:

<au>J. Fred Muggs</au>

So now you can write an agent to do something with your tagged text. In this case, I'm setting my user attribute $Author to "J. Fred Muggs":

Query:  Text((<au>)(.+)(</au>))
Action: $Author=$2

Assigning the Applescript to a keypress is difficult for two reasons. First, I don't think that the standard Applescripts Menu supports the Barebones filenaming conventions: "___Cmd-G.scpt" and the like. Second, so many key combinations are taken already (by TB and others) that it's hard to assign good ones. Currently I'm trying out FastScripts and assigning the F-keys to trigger the scripts.

Hope someone out there finds this useful, or perhaps can suggest improvements.

I do have one TB question: I have a few "global" agents that set attributes and then aren't needed anymore, but I'd like to keep them around. Is there some way of "turning off" selected agents so they don't run (although others agents would still be active)?

Best, Charles

Title: Re: Tagging with Applescript
Post by Mark Anderson on May 4th, 2009, 10:17am


Quote:
I do have one TB question: I have a few "global" agents that set attributes and then aren't needed anymore, but I'd like to keep them around. Is there some way of "turning off" selected agents so they don't run (although others agents would still be active)?

Look up the AgentPriority attribute (here and here might help). You can either manually set the AgentPriority from the agent's create/rename dialog or Info view, or you can set it via an action.

With its AgentPriority set to 0, the agent is effectively 'frozen' and will continue to contain the aliases of the notes currently matched at the time the agent was turned off. The outline icon for frozen agents is also slightly different.

Do take care to ensure that any running agents/tasks don't require the work of the agent's you've now frozen. I've found that's easier to do than one might think, but boils down to you knowing your TBX as the app can't guess your real intent in this context.

Title: Re: Tagging with Applescript
Post by Charles Turner on May 4th, 2009, 11:49am

Very nice, Mark, thanks! Your Tinderbox reference is really lovely...

Title: Re: Tagging with Applescript
Post by Johnnie Wilcox - mistersquid on May 4th, 2009, 12:59pm

Don't bother with FastScripts. It's event logging framework doesn't work for some programs.

A much more robust tool is Keyboard Maestro, which allows you to assign keyboard shortcuts to AppleScripts and much much more. You can even script Tinderbox actions, menu items, and button presses.

I have no affiliation with Keyboard Maestro except that I am a *very* satisfied user.

Title: Re: Tagging with Applescript
Post by Charles Turner on May 4th, 2009, 2:53pm

I had looked at Keyboard Maestro about a year ago, along with Quickeys, and I think I didn't get excited about it because I wanted mouse triggered actions. A quick scan just now suggests that Keyboard Maestro has a lot better clipboard support than Quickeys.

I ultimately got more excited about Prefab's UI Browser than either of the above, although it's a less casual experience. I particularly hate Quickeys macro editor.

Keyboard Maestro looks like it's worth another look, if only because it might replace Fastscripts, Witch, PTHPasteboard and maybe Xmenu.

Thanks for the tip! Charles


Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.