Re: How to accept drag of a URL on the dock icon?
Re: How to accept drag of a URL on the dock icon?
- Subject: Re: How to accept drag of a URL on the dock icon?
- From: Andy Lee <email@hidden>
- Date: Sun, 22 Dec 2013 14:48:35 -0500
Thanks, Ken. I stumbled onto the solution by way of an old page about how to drag text snippets onto the dock icon in an PyObjC app. Who knows how long I'd have been scratching my head if I hadn't guessed the same approach might work for URLs.
For a minute it looked like I could use the same code to handle files dragged to the dock icon from the Finder. My service did get invoked, and it was passed an NSPasteboard that was superficially similar in that it contained URLs, in this case file URLs rather than web URLs. But when I tried to iterate through the file URLs I got messages like this:
2013-12-22 14:43:32.732 DockHow[34606:303] Failed to get a sandbox extensions for itemIdentifier (1). The data for the sandbox extension was NULL
I didn't feel like messing with sandbox stuff, so I implemented application:openFiles: in addition to the service. And now I don't remember if that worked, because I decided I didn't really need to accept dragged URLs after all! But still, good to know for future reference.
--Andy
On Dec 21, 2013, at 7:48 PM, Ken Thomases <email@hidden> wrote:
> For what it's worth, this is documented somewhat in Cocoa Scripting Guide: How Cocoa Applications Handle Apple Events – Apple Events Sent by the Mac OS – Open Contents.
> https://developer.apple.com/library/mac/documentation/cocoa/conceptual/ScriptableCocoaApplications/SApps_handle_AEs/SAppsHandleAEs.html#//apple_ref/doc/uid/20001239-1121328
>
> Cheers,
> Ken
>
> On Dec 21, 2013, at 5:22 PM, Andy Lee wrote:
>
>> To answer my own question, it looks like it's done by implementing a Service. I've gotten it working in a quick scratch application.
>>
>> --Andy
>>
>> On Dec 21, 2013, at 6:06 PM, Andy Lee <email@hidden> wrote:
>>
>>> I know how to accept files that are dragged from Finder to the application icon. It's a matter of adding some settings to Info.plist and implementing the application:openFiles: application delegate method.
>>>
>>> This does not work for dragging URLs from a web browser -- for example, dragging from Safari's URL field, or dragging an image being displayed in Safari to the dock icon. What happens is, my application:openFiles: method is never called, and the URL is given back to Safari to reload.
>>>
>>> Yet it is clearly possible for applications to accept dragging of URLs to their Dock icons, because it works for other browsers. What are those other browsers doing?
>>>
>>> I tried using a custom contentView for the dock tile, and having that view be a drag destination (call registerForDraggedTypes: and implement NSDraggingDestination methods). But that didn't make any difference.
>>>
>>> --Andy
>>
>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> 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:
>>
>> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden