> and without knowing what others have said, I can surmise that their replies > where no less perplexed with the question "but Why?"
This gloriously ugly hack isn't the correct "why" question - the correct "why" question is "why do I even need to do it?" I want to be able to copy the current selection from another app so I can use it in mine w/o requiring the user to do the copy first themselves. The standard hacks when slogging through the net about this are to either use an Apple Script along these lines (some advocate opening up the Edit Menu then selecting the Copy item, which is comparably fragile), or packing up and sending in Apple Events to emulate the keypress. As I understand it, those are fragile for different reasons. But other than resorting to hacks like this there is, AFAIK, no way to get the selected text from any other arbitrary app. If you have a better solution, I'd love to hear it. Using the pasteboard isn't the right approach at all, since there's no data on the pasteboard as of yet. I'd need to get it onto there before it can be copied off. And no, before it's suggested, using a service isn't appropriate in this case for several reasons, mainly that I want to invoke my app with some input (or no input), and then conditionally provide output. I'd love to use a service instead, but AFAIK it won't bend to those constraints. So back to my original question and issue - this hack works great when run from Script Editor, but when invoked via NSAppleScript. It will -sometimes- work if I embed a standalone script into my app and shell out to it. Oddly enough, I discovered quite by accident that if I left both in there (both invoking via NSAppleScript AND shelling out to the external one), it'll always work. But that's a hack bordering on the insane. I assumed that it was somehow a timing issue and that by doing it twice I was slowing things down enough for it not to trigger, but I wasn't able to fix it by adding delays into my app anywhere. The two calls is the only approach I've got functional right now. -Jim.... _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com