[TxMt] Slow osascript in drag command

Dr. Drang drdrang at gmail.com
Fri Dec 14 03:55:51 UTC 2007


I learned a few days ago (see http://xrl.us/bcuzs) that a drag  
command with a file type of "vcf" will work on cards dragged out of  
the Address Book as well as vcf files dragged from the Finder. (A  
temporary vcf file is made as you drag the card.) I thought it would  
be nice to have a formatted name and address appear in the TM window  
instead of the default vCard-formatted info. I had an AppleScript I'd  
written a while ago that I adapted for this purpose and called it  
from the drag command using 'osascript'.

The drag command works, but it takes 20-30 seconds to run when  
operating on a card dragged from the Address Book. This isn't because  
the AppleScript itself is slow--it runs almost instantly when  
operating on a vCard file dragged from the Finder.

In the interests of space, here's a simpler AppleScript that exhibits  
the same difference in runtime:

     on run argv
       tell application "Address Book"
         set theCard to (person id (item 1 of argv))
         set out to name of theCard
       end tell
       return out
     end run

I've called it "abname.scpt" and saved it in my ~/bin directory.  
(I've also saved it as an application and as text. The results are  
the same.)

Here's the drag command:

     if [[ $TM_MODIFIER_FLAGS = "OPTION" ]]; then
       uid=`cat "$TM_DROPPED_FILE" |\
       awk -F: '/^X\-ABUID/\
       {printf "%s:ABPerson", substr($2,1,length($2)-1)}'`
       osascript $HOME/bin/abname.scpt "$uid"
     else
       cat "$TM_DROPPED_FILE"
     fi

This is set up so that when I hold the Option key down as I drag, the  
name of the card is inserted in the TM window. If I *don't* hold the  
Option key down, the usual vCard data is inserted. The behavior on my  
main computer--an Intel iMac running OS X 10.4.11 with TM 1.5.7  
(1436)--is like this:

Dragging from       Option key          Time to run
----------------------------------------------------
file in Finder      not pressed           instant
file in Finder      pressed               instant
card from AB        not pressed           instant
card from AB        pressed             20+ seconds

I'd like to know why there's such a difference and what I can do, if  
anything, to speed things up.


--
Dr. Drang



More information about the textmate mailing list