Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

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


macrumors newbie
Original poster
Jan 14, 2012
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:

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

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\" \"\">
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
    <meta http-equiv=\"Content-Style-Type\" content=\"text/css\">
  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}
  <p class=\"p1\"><a href=\""
  set html_3 to "\">"
  set html_4 to "</a></p>
  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:

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.