[TxMt] BibDesk

Allan Odgaard allan at macromates.com
Wed Apr 13 21:10:50 UTC 2005

On Apr 13, 2005, at 16:26, Thomas Schröder wrote:

> 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".

Ah yes -- I didn't realize it was a sub-string search. What you could 
do is start the command like this:

if [[ -z $TM_SELECTED_TEXT ]]
    then phrase=$TM_CURRENT_WORD
    else phrase=$TM_SELECTED_TEXT

and then search for "$phrase", which will be current word when there is 
no selection. You'd need a similar 'if' construct when returning the 
result, so to cut the prefix when doing current word search.

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

I was indeed a bit puzzled by what it returned :)

> 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`

Okay, here's my take on it:

    osascript -e 'tell app "TextMate" to activate' &>/dev/null &
    awk <<<$res '{print $1}' | tr -d \\n

Or if you want to keep the comment but insert a bracket:
    perl <<<$res -pe 's/^(\w+)/$1}/'

So the entire command (with the condition on selection) becomes:
if [[ -z $TM_SELECTED_TEXT ]]
    then phrase=$TM_CURRENT_WORD
    else phrase=$TM_SELECTED_TEXT

res=`osascript <<EOF
	tell application "Bibdesk" to set candidates to search for "$phrase" 
with for completion
	tell application "System Events"
		choose from list candidates
	end tell
osascript -e 'tell app "TextMate" to activate' &>/dev/null &

res=`perl <<<$res -pe 's/^(\w+)/$1}/'`
if [[ -z $TM_SELECTED_TEXT ]]
    then echo -n ${res:${#TM_CURRENT_WORD}}
    else echo -n $res

More information about the textmate mailing list