girton’s devnotes

ongoing developer notes  
Filed under

applescript

 

a web clip script for Safari and Mail

Finally I gave up and coded some AppleScript at the end of the day -- I wanted to be able to mail a web clip with the URL, title, and my selected text. The URL (shown after the script) was helpful in showing how to set up the script menu. There wasn't a scriptmenu.menu in my Applications/Applescript folder, but something called script utility that gave me the same option.
 
tell application "Safari"
  set intro_text to "Here is a clip from"
  set page_title to (do JavaScript "document.title" in document 1)
  set that_URL to (get URL of document 1)
  set selected_text to (do JavaScript "(getSelection())" in document 1)
end tell
 
tell application "Mail"
  activate
  set newline to ASCII character 10
  set this_message to make new outgoing message with properties {visible:true, subject:"a web clip from George", content:(page_title & newline & "[ " & that_URL & " ]" & newline & newline & selected_text)}
end tell
 

 

Here's the link to MacOSX Hints:
  macosxhints.com - An AppleScript to email Safari URLs with titles via Mail
 
[ http://www.macosxhints.com/article.php?story=20030318202727875 ]
 
[robg adds: Save this script as a compiled script in your user's Library -> Scripts folder, and then just activate it using the ScriptMenu icon when you need it. Very handy! As an aside, activate the ScriptMenu by double-clicking ScriptMenu.menu in the Applications - > AppleScript folder.]

Loading mentions Retweet
Filed under  //   AppleScript  
Posted by George Girton 

Comments [1]