I'm currently trying to modify the default URL handling behavior in OS X. I would like, when clicking on any link outside of a web browser, to copy this URL to the pasteboard instead of opening it in the default web browser – for instance, clicking a link in a Skype conversation should copy this URL to the OS X pasteboard instead of opening it in Firefox (which is currently my default web browser).

I have thought about solutions, but I’m currently unable to implement one. If I can create an application that puts URLs into the pasteboard that are sent to it, and can set this application as the default web browser, I would be able to achieve my goal.

I created an application with Automator that executes the shell command pbcopy and have set this application as my default web browser, but I didn’t get the expected result. I did some testing and I can confirm that the application runs on clicking on a link, however, I cannot get the URL passed to the application / shell script. I tried both stdin or a passed argument, but without success.

Is there a way for an application created with Automator to retrieve a clicked URL and send it to pbcopy, when that application is set as a (default) handler for URLs?

Alternatively, is there a better way to create a fake web browser that takes the input and puts it in the pasteboard than Automator? Or is there any other way that I can achieve my goal without a custom application / script?

  • Not putting this as an answer since it's not a complete solution, but it's a start - I used rubicode.com/Software/RCDefaultApp to set an automator application as the default browser. In Automator, there is an action to Copy to Clipboard. I just can't get any text input to an automator app. – penguinrob Mar 29 '12 at 22:35
  • Ditto, but I used Choosy. I've done a fair amount of testing, and I've found the following: 1) The Automator app does run. 2) It doesn't seem to get any sort of input at all. 3) Ergo, when a browser is sent a "link", it is not sent a URL in plaintext. This must be handled in some different way, and that's really what the question is after. – Timothy Mueller-Harder Mar 29 '12 at 23:59

The way URL opening in Mac OS X is actually more complicated than you would think. When you click a URL, Mac OS X does not just pass the browser the URL to open; instead, it sends it an Apple Event, with the ID kAEGetURL, containing the URL.

I never really used Automator (it's just way too slow and limited for my typical use), so I'm not sure about this, but I doubt it has the ability to handle Apple Events. Therefore you won't be able to use Automator to achieve what you want.

You'll therefore have to resort to a normal Objective-C app in Xcode.

The two basic things you need to do are:

  1. register your app for receiving the kAEGetURL event, and set the CFBundleURLTypes in your app's Info.plist to include http and https.

  2. Implement a method handling the kAEGetURL event, and make it copy the URL to the clipboard.

These two things are relatively straightforward to do in Objective-C; to illustrate, I've created a sample application that does this. You can view it at https://github.com/houbysoft/short/tree/master/Copy%20URL%20to%20Clipboard. The most important file is https://github.com/houbysoft/short/blob/master/Copy%20URL%20to%20Clipboard/Copy%20URL%20to%20Clipboard/AppDelegate.m, there you can see how to register for the event (this is done in the applicationWillFinishLaunching: method) and how to copy it to the clipboard (this is done in the getUrl:withReplyEvent: method).

If you're feeling lazy and just want to see that this works, grab this file, extract the application from it, set that as the default web browser (open Safari Preferences, and browse for that app in the Default web browser field). Then click on your link in Skype, and it should be copied straight to your clipboard.

  • Thank you for your answer. I didn't know how URL was proceed in OSX. I have take a look at your code, but I don't know Objective-C very much. But, your resulting application work like a charm and that what I wanted from the beginning. Thanks again! – DjDCH Apr 2 '12 at 4:43
  • Nice work on the app(let). I’d love to bestow the bounty, but I’m missing some definitive info on the question if Automator can (or cannot) be coerced to acknowledge a kAEGetURL event to do that. – kopischke Apr 3 '12 at 10:39
  • @kopischke: I just searched the Automator help for any mention of Apple events, and nothing was found. I think it's fair to assume Automator does not support this. – houbysoft Apr 5 '12 at 2:20
  • It is possible to do this with AppleScript, which would be the "logical" way to extend an Automator workflow, without delving into XCode / ObjC and compiling your own app. (not that it's all that complicated, but it's likely AppleScript would be easier.) – ocodo Oct 30 '15 at 4:50
  • This does not seem to work on 10.11. "/Applications/Copy URL to Clipboard.app is not available as a HTTP browser" – TJ Luoma Dec 2 '15 at 22:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .