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
On 14 Dec 2007, at 04:55, Dr. Drang wrote:
[...] 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.
This is just a hunch, but maybe holding down the option key has AB do something special.
Try e.g. swap the behavior of what to do when option is held/released and/or try another modifier key, see if that changes things.
20+ seconds stall does however sound very much like something times out.
On Dec 18, 2007 12:39 PM, Allan Odgaard throw-away-2@macromates.com wrote:
This is just a hunch, but maybe holding down the option key has AB do something special.
Try e.g. swap the behavior of what to do when option is held/released and/or try another modifier key, see if that changes things.
20+ seconds stall does however sound very much like something times out.
I'll see what happens when it's not tied to the Option key the next time I'm at my Tiger machine. I think I did once have it tied to the Shift key, but I may be misremembering.
I just discovered that the issue may be moot. When trying to test your suggestions on a Leopard machine, I found that its Address Book doesn't allow the dragging of cards to TextMate. Don't know if this has more to do with TM than AB (does TM have to be "registered" in some way to accept AB cards)), but since my Tiger machine will be updated in the next few weeks, any fix will be short-lived.
On 19 Dec 2007, at 00:45, Dr. Drang wrote:
[...] I just discovered that the issue may be moot. When trying to test your suggestions on a Leopard machine, I found that its Address Book doesn't allow the dragging of cards to TextMate. Don't know if this has more to do with TM than AB (does TM have to be "registered" in some way to accept AB cards))
TM would have to explicitly register for non-file/text types. But it would also have to have code to actually handle that drop. I.e. if AB does not provide the info as a file, there is presently no system for the drop command to actually get to the data.
On Dec 20, 2007 3:45 PM, Allan Odgaard throw-away-2@macromates.com wrote:
TM would have to explicitly register for non-file/text types. But it would also have to have code to actually handle that drop. I.e. if AB does not provide the info as a file, there is presently no system for the drop command to actually get to the data.
Apple clearly changed something. In Tiger, a drag command for "vcf" files that was simply 'echo $TM_DROPPED_FILE` would insert some temporary file name when invoked by dragging a card directly from AB. Presumably, that temporary file was the reason the drag command worked. Maybe Leopard has "streamlined" things to where the temporary file is no longer made.
Frankly, I was surprised when dragging a card from AB to TM worked in Tiger. I'll just have to decide on another way of transferring the information.
On Dec 18, 2007, at 12:39 PM, Allan Odgaard wrote:
This is just a hunch, but maybe holding down the option key has AB do something special.
Try e.g. swap the behavior of what to do when option is held/ released and/or try another modifier key, see if that changes things.
No, the Option key has nothing to do with it. I changed the drag command to
uid=`cat "$TM_DROPPED_FILE" |\ awk -F: '/^X-ABUID/\ {printf "%s:ABPerson", substr($2,1,length($2)-1)}'` osascript $HOME/bin/abname.scpt "$uid"
and it still takes 20+ seconds to run when dragging a card directly from Address Book.
As I said in my message yesterday, dragging a card from AB doesn't work at all in Leopard, so maybe this isn't worth pursuing.
-- Dr. Drang