Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.6: Create an RTF-formatted link to current Safari page Web Browsers
Snow Leopard only hintTo copy a clickable hyperlink of the currently shown website from Safari (with the website title and its URL embedded in it) to the clipboard, in order to paste it somewhere else, you would have to: Open a rich text editor, drag the link from the Safari URL bar to the text editor, Control-click on the created hyperlink, and finally, click on Copy Link. This is tedious work. Safari should have a "copy hyperlink to clipboard" button.

Because it didn't, I wrote my own Service in 10.6 to get the job done. Here's how:
  1. Open Automator and create a new Service. In the Service Receives section, set the two drop-down menus to No Input and Any Application.
  2. Find and drag the Run AppleScript action into the work area.
  3. Paste the following AppleScript into the code box in the action item:
  4. tell application "Safari"
      set theURL to URL of document 1
      set theTitle to name of document 1
      
      set startEcho to "echo "
      set echoDelimiter to "'"
      
      set html_1 to "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
      <html>
      <head>
        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
        <meta http-equiv=\"Content-Style-Type\" content=\"text/css\">
        <title>"
      set html_2 to "</title>
        <meta name=\"Generator\" content=\"Cocoa HTML Writer\">
        <meta name=\"CocoaVersion\" content=\"1038.11\">
          <style type=\"text/css\">
            p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
          </style>
        </head>
      <body>
      <p class=\"p1\"><a href=\""
      set html_3 to "\">"
      set html_4 to "</a></p>
      </body>
      </html>"
      
      set echoCommand to startEcho & echoDelimiter & html_1 & theTitle & html_2 & theURL & html_3 & theTitle & html_4 & echoDelimiter
      set textutilCommand to " | textutil -convert rtf -inputencoding UTF-8 -format html -stdin -stdout"
      set pbcopyCommand to " | pbcopy -Prefer rtf"
      
      set entireCommand to echoCommand & textutilCommand & pbcopyCommand
      
      do shell script entireCommand
    end tell
    This AppleScript sends a string that contains the website title and URL in html format to the terminal program textutil. textutil converts that HTML string into an RTF-formatted string and sends it to pbcopy, which copies the string to the Mac OS clipboard.
  5. Save this Service with any name you like.
  6. Open System Preferences » Keyboard, and select Services in the left-hand column.
  7. Select the Service you just created, and define a keyboard shortcut for it.
Now, every time you press that shortcut, from any Services-aware application, a clickable hyperlink with the title and the embedded URL of the currently-active Safari tab will be copied to the Mac OS clipboard, ready to be pasted in any other application. This works great with an app that keeps track of your recent clipboard items.

[robg adds: This works fine in 10.6, and can be used in 10.4 and 10.5 as well, though not as a Service. Because textutil was added in 10.4, this hint won't work in older system releases.]
    •    
  • Currently 1.30 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (10 votes cast)
 
[7,063 views]  

10.6: Create an RTF-formatted link to current Safari page | 22 comments | Create New Account
Click here to return to the '10.6: Create an RTF-formatted link to current Safari page' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Drag and drop from location bar to create hyperlink
Authored by: jfaughnan on Oct 21, '09 09:11:18AM

I assume you knew that you can click on a location bar URL and drag it onto a Rich Text Editor surface to create a hyperlink with the page title as text?

---
--
John Faughnan
jfaughnan@spamcop.net
www.faughnan.com



[ Reply to This | # ]
Works without going back to the browser window...
Authored by: gabester on Oct 21, '09 09:24:47AM

I just spent a goodly portion of the morning understanding what this hint is supposed to accomplish over simply dragging from the URL in Safari to your rich-text enabled application.

I believe it is that you can run this shortcut from ANY application to get the URL from the frontmost window in Safari into the clipboard. Which is actually kind of handy... however, this hint does not work out of the box if you're using a customized Safari4 beta with tabs on top (unsurprisingly.)

[ Reply to This | # ]

10.6: Create an RTF-formatted link to current Safari page
Authored by: AndyB2 on Oct 21, '09 09:21:32AM

or you could simply hold the mouse on the link in Safari and drag it to Text Edit :)

( or did I miss something subtle ? )



[ Reply to This | # ]
10.6: Create an RTF-formatted link to current Safari page
Authored by: everkleer80 on Oct 21, '09 09:28:35AM

Alucard mentioned that you could do that:

>> ...Open a rich text editor, drag the link from the Safari URL bar to the text editor, Control-click on the created hyperlink, and finally, click on Copy Link. This is tedious work. Safari should have a "copy hyperlink to clipboard" button.

This is to create a quick copy without opening any other programs.



[ Reply to This | # ]
10.6: Create an RTF-formatted link to current Safari page
Authored by: gabester on Oct 21, '09 09:31:31AM

Interestingly, having a button to do this in Safari would seem to defeat the primary purpose of this hint as I've perceived it, namely that you can get the frontmost Safari window's URL as a hyperlink named for the page title into the clipboard. I suggest extending the AppleScript to execute a pbpaste from the clipboard at the end of the script to spare the (custom keystroke used for the service) followed by command-v to paste the clipboard.



[ Reply to This | # ]
10.6: Create an RTF-formatted link to current Safari page
Authored by: gabester on Oct 21, '09 10:38:35AM

OK, I take it back... for this hint to work the URL in Safari has to already be highlighted, necessitating that one clicks back away from the current app to Safari anyway... which makes it just as easy to drag and drop as to do this, in my view.

But it seems to have promise if implemented as I outlined.



[ Reply to This | # ]
10.6: Create an RTF-formatted link to current Safari page
Authored by: everkleer80 on Oct 21, '09 12:17:54PM

As I tried to say in my previous post, I think the whole point of this is just to copy the link to the clipboard, not to put it in TextEdit or any other app. If it is on the clipboard then you can paste it however many times you want, whenever you want (maybe you want to copy it to use at a later time) and, as the OP said, this is particularly useful with a clipboard monitoring program such as JumpCut.



[ Reply to This | # ]
Safari 4 Action menu
Authored by: frank_martin on Oct 21, '09 12:16:38PM

There is an Action (Gear) optional toolbar element available in Safari 4. Among other things, it offers "Copy Link HTML Tag" that appears to perform the same function as this post, available regardless of OS version.

To instate this, do View menu > Customize toolbar and drag the Action/Gear icon to your toolbar.



[ Reply to This | # ]
Safari 4 Action menu
Authored by: everkleer80 on Oct 21, '09 12:27:12PM

Great find!



[ Reply to This | # ]
Safari 4 Action menu
Authored by: rgray on Oct 21, '09 01:24:11PM
I am in Safari 4.0.3. What "Action (Gear)" icon? This is my Customise Toolbar screen

[ Reply to This | # ]
Safari 4 Action menu
Authored by: frank_martin on Oct 21, '09 03:07:52PM

Sorry, I don't know why you do not have that.

On my Leopard machine and on my Tiger machine, it is located just right of the Google toolbar element in your screenshot.

Perhaps reinstall Safari?



[ Reply to This | # ]
Safari 4 Action menu
Authored by: tedw on Oct 21, '09 03:44:37PM

double-check that you didn't accidentally open the wrong version of Safari, because that's not the correct toolbar collection (t least not for Leopard - are you using Tiger?). If you have the correct version, than something's amiss; I'd go to the Apple download page and download a fresh version of Safari.



[ Reply to This | # ]
Safari 4 Action menu
Authored by: tedw on Oct 21, '09 03:44:37PM

double-check that you didn't accidentally open the wrong version of Safari, because that's not the correct toolbar collection (t least not for Leopard - are you using Tiger?). If you have the correct version, than something's amiss; I'd go to the Apple download page and download a fresh version of Safari.



[ Reply to This | # ]
Safari 4 Action menu
Authored by: everkleer80 on Oct 21, '09 04:15:06PM

Mine is the same (also in 4.0.3.) I was actually going to dl a new copy as you suggest but I notice there is no Snow Leopard version available (odd being THE Apple site...) and I didn't know if I should use the Leopard version. Perhaps this button was removed in SL though?



[ Reply to This | # ]
Safari 4 Action menu
Authored by: frank_martin on Oct 22, '09 10:37:23AM

Confirmed, this button is omitted in SL.



[ Reply to This | # ]
Safari 4 Action menu
Authored by: auco on Oct 22, '09 06:53:42AM

I have a gear icon that provides various useful things amongst copying the URL w/ title (eg. saving flv's), but I think it came with Safari Stand.

Cheers,
Michael



[ Reply to This | # ]
Safari 4 Action menu
Authored by: frank_martin on Oct 22, '09 11:19:17AM

This is correct. I did have SafariStand installed, and removing it removed the gear/Action menu.

My apologies to those who were puzzled by its absence. The good news is that installing SafariStand (freeware) gets this feature for you, and it is SL/64-bit-compatible.

http://www.versiontracker.com/dyn/moreinfo/macosx/26421



[ Reply to This | # ]
10.6: Create an RTF-formatted link to current Safari page
Authored by: robleach on Oct 21, '09 01:00:08PM

I figure this solution must be solving a problem which I have not yet encountered because I do not understand how this solution is different from copying the URL directly from a Safari location bar (other than as stated in other comments, you don't need to switch to Safari to do the copy). But if that's the case, why bother dragging the URL to a rich text editor in the stated "tedious" method. Doesn't copying the URL from the Safari location bar save you the step of pasting in a rich text editor and control-clicking that to select copy link? When I try that, and paste into 1. a plain text document or 2. a rich text document, I get 1. the full URL and 2. the title of the web page hyperlinked to the page itself. I get the exact same behavior if I use the tedious method that was described. What am I missing?

What I would like to know is how to paste the full URL into a rich text editor instead of getting the hyperlink. Got a solution for that?



[ Reply to This | # ]
10.6: Create an RTF-formatted link to current Safari page
Authored by: everkleer80 on Oct 21, '09 01:44:43PM

Maybe there is a hidden setting you turned on somewhere or you're using a plug-in or something that let's you do this? Because whenever I copy the URL (Just click in the text box with the URL in it and hit CMD-C right?) and then paste it in iChat or whatever, it copied the actual address. And I'd assume the OP experiences the same behavior and that's why the hint was created...



[ Reply to This | # ]
10.6: Create an RTF-formatted link to current Safari page
Authored by: robleach on Oct 22, '09 11:00:06AM

Hmmm... I haven't installed any plugins aside from flash-related things. Definitely haven't installed anything to specifically solve this specific issue, however I dug a little further with some experimenting and discovered this:

1. If I click & hold on the highlighted URL in the location field & drag it (which I never personally do) to a rich text document, it pastes the un-hyperlinked full URL.
2. If I instead click-drag the favicon (which I always personally do) to a rich text document, it pastes the page title hyperlinked to the URL.

Try it. I'll bet it works for everyone, thus making the only thing this hint added in terms of features, the ability to copy the hyper-linked version without the need to click & drag (or to even go to the Safari window). Otherwise, anyone can drag the favicon to get the hyperlink.

Rob



[ Reply to This | # ]
10.6: Create an RTF-formatted link to current Safari page
Authored by: everkleer80 on Oct 28, '09 09:57:54PM

Oh, you're absolutely right, I just misunderstood your first post. You're right, the advantage of this hint is to be able to copy from within Safari without the need for TextEdit or any other program to be open.



[ Reply to This | # ]
Copy link through Safari
Authored by: everkleer80 on Oct 21, '09 04:48:40PM

All this talk of supposed alternative methods of doing this from within Safari has got me trying to figure out a way to do it. You can alway go to your history (History - Show All History -- no hotkey but one could be created) and then copy the item from there, and you can also right/ctrl-click bookmarks in the toolbar to do this (and you can drag the current url to the bookmark bar if it's not already there) but all of these involve some work. If the goal is to get the link onto the clipboard then the service in this hint is definitely the best way. Another thing you could do if you don't want or can't use a service (ie. previous os) is create an automator app that you could just drag the link to and it would copy it to the clipboard.



[ Reply to This | # ]