Fully automated, one-step sending of a URL from Safari

Feb 22, '08 07:30:05AM

Contributed by: Anonymous

I often send a link off to one single person, many times a day. You can use the Mail Link to this Page feature in Safari, but that still means you have to compose the email with the To address, and also tell the email to send. Since I do this several times a day, I decided to AppleScript it. Drop the following script into ~/Library » Scripts » Safari; name it what you like. If that folder structure is not already made, just make new folders with the correct names.

The script will get the current URL of the frontmost document in Safari. It will not copy it to the clipboard, leaving your clipboard in the same state. The script them brings Mail.app forward, addresses an email, sets a subject, some body copy, and drops the URL into the email. Finally, a signature is added to the message, and it is sent out. After that has happened, Mail.app is set to hidden, and Safari is brought back to the foreground where you last left it.

Here's the script:

-- Script made by Scott Haneda
-- http://osxhelp.com
-- 02/13/2008

-- Get the current URL
tell application "Safari"
  set thisPage to do JavaScript "document.URL" in document 1
end tell

-- Create a new email message in mail.app
tell application "Mail"
  activate
  set this_message to make new outgoing message at beginning of every outgoing message
  tell this_message
    make new to recipient at beginning of to recipients ¬
      with properties {address:"firend@example.com", «class rdsn»:"FirstName LastName"}
    set the subject to "The email subject"
    set the content to "Hey, I thought you would be interested in this link: 
" & thisPage & "

--
Signature Name"
  end tell
  send this_message -- Send the email message
end tell

-- Restore Safari to the foreground, hide mail.app
tell application "System Events" to set visible of first process whose name is "Mail" to false
tell application "Safari"
  activate
end tell
In /Applications » AppleScript is a program called AppleScript Utility. This will enable the script menu item in the Finder. Personally, I have attached this script to a keyboard command with Keyboard Maestro. You can also use FastScripts Lite, which is free.

Comments (14)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080213202340174