Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Tagging with Applescript (Read 5049 times)
Charles Turner
Full Member
*
Offline



Posts: 180
New York, USA
Tagging with Applescript
May 04th, 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
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Tagging with Applescript
Reply #1 - 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.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Charles Turner
Full Member
*
Offline



Posts: 180
New York, USA
Re: Tagging with Applescript
Reply #2 - May 4th, 2009, 11:49am
 
Very nice, Mark, thanks! Your Tinderbox reference is really lovely...
Back to top
 
 
WWW   IP Logged
Johnnie Wilcox - mistersquid
Full Member
*
Offline



Posts: 84
San Francisco, CA
Re: Tagging with Applescript
Reply #3 - 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.
Back to top
 
« Last Edit: May 4th, 2009, 1:00pm by Johnnie Wilcox - mistersquid »  
  IP Logged
Charles Turner
Full Member
*
Offline



Posts: 180
New York, USA
Re: Tagging with Applescript
Reply #4 - 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

Back to top
 
« Last Edit: May 4th, 2009, 5:01pm by Charles Turner »  
WWW   IP Logged
Pages: 1
Send Topic Print