Apple Script help. Insert rich text link from Safari with TextExpander

Dynamitleo

macrumors newbie
Original poster
Jan 14, 2012
5
0
Hi
I would like to have an TextExpander-snippet that create a RTF-formatted link of the current Safari page.
Like this: MacRumors: Apple Mac iPhone Rumors and News in stead of this: https://www.macrumors.com

I found this great Apple Script (Credit alucard from Mac OS X Hints):

AppleScript:
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
Can anybody help me tweak it so that i can enter it in TextExpander?Currently im using this simple script, but it only returns a plain text link:

AppleScript:
tell application "Safari" to return URL of current tab of window 1
Thanks :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.