Oct 21, '09 07:30:04AM • Contributed by: alucard
To 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:
- Open Automator and create a new Service. In the Service Receives section, set the two drop-down menus to No Input and Any Application.
- Find and drag the Run AppleScript action into the work area.
- Paste the following AppleScript into the code box in the action item:
- Save this Service with any name you like.
- Open System Preferences » Keyboard, and select Services in the left-hand column.
- Select the Service you just created, and define a keyboard shortcut for it.
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[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.]
