[TxMt] BibDesk

Thomas Schröder hydrochlorix at gmx.net
Wed Apr 13 14:26:51 UTC 2005


Am 13.04.2005 um 03:21 schrieb Allan Odgaard:

Thanks for your quick and comprehensive reply!

> I'm not exactly sure how BibDesk works -- it does install an input 
> manager, but maybe this is to patch the NSTextView of the application, 
> in which case it won't work with TM.

Ah, that's maybe it. Oh, well.

> However, BibDesk does support AppleScript to lookup a search string 
> for completion, so what you can do is go to menu Automation / Run 
> Command / Edit Commands...
>
> Make a new command with input: none, output: insert as snippet, key 
> equivalent: option-escape and the actual command:
>
> res=`osascript <<EOF
>    tell application "Bibdesk" to set candidates to search for 
> "$TM_CURRENT_WORD" with for completion
>    tell application "System Events"
>       activate
>       choose from list candidates
>    end tell
> EOF`
> osascript -e 'tell app "TextMate" to activate' &>/dev/null &
> echo -n ${res:${#TM_CURRENT_WORD}}
>
> If you type something, press option-escape, it will lookup the word to 
> the left of the caret, showing matches (from BibDesk) using an AS 
> dialog, and if you select one, it'll insert that choice.
>
> I have added the script to the subversion repository (in the LaTeX 
> bundle), incase anyone wishes to improve it (like not showing the 
> dialog for a single match, handling “cancel” and zero matches (though 
> which BibDesk doesn't seem to give) etc.).

I changed this command a little to my needs for two reasons:

1. This works great if you type the beginning of the cite-key e.g. "Od" 
for "Odgaard2005" but if you type something from the title e.g. "Te" 
you'll get something like "Tegaard2005".

2. BibDesk gives the reference in the following format: "cite-key % 
author, title" e.g.

Odgaard2005 % Odgaard, TextMate - An insanely great new text editor

This is great as such when you want to chose the right item from the AS 
dialog, but when this string gets inserted, there's the problem that 
the ending brace from the \cite{} command will be uncommented thanks to 
BibDesk's percent sign which of course will give you trouble on the 
next LaTeX run. I could of course fix this by hand for every entry, but 
what do I have a computer for, I said to myself :-)

So, here goes: Input - Selected Text; Output - Replace Selected Text;

----

res=`osascript <<EOF
    tell application "Bibdesk" to set candidates to search for 
"$TM_SELECTED_TEXT" with for completion
    tell application "System Events"
       activate
       choose from list candidates
    end tell
EOF`
echo -n ${res} > /tmp/BibDesk_Completion.txt
osascript -e 'tell app "TextMate" to activate' &>/dev/null &
#perl -pe 's/ %/} %/' /tmp/BibDesk_Completion.txt
cat /tmp/BibDesk_Completion.txt | awk '{print $1}' > 
/tmp/BibDesk_Completion.txt
echo -n `cat /tmp/BibDesk_Completion.txt`
----

If I were a little more versatile with perl I would have actually 
gotten rid of everything except the cite-key but I couldn't so I used 
awk to do that for me. But maybe some kind soul out there is more savvy 
than me :-)

I also realize that creating the temporary file is a bit of kludge, but 
it's that versatility thing again :-)

Finally, I realize that having now to select the text is not as elegant 
as your solution but I don't see any other way if I want to use other 
bits than just the beginning of the cite key.

Anyways, thanks again for the quick reply and for TextMate, it really 
is insanely great! As for the above, maybe somebody will find this 
useful, I certainly do.

Best wishes, Thomas



More information about the textmate mailing list