Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Fully automated, one-step sending of a URL from Safari Web Browsers
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.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[10,139 views]  

Fully automated, one-step sending of a URL from Safari | 14 comments | Create New Account
Click here to return to the 'Fully automated, one-step sending of a URL from Safari' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Fully automated, one-step sending of a URL from Safari
Authored by: scottdb on Feb 22, '08 09:27:28AM

'Command - Shift - I' pretty much does this already, yes?



[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: rgray on Feb 22, '08 09:36:51AM

Certainly does for me. I want to personalise the reference to make it personal and individual. I do not want to dump in some canned text which seems kinda like SPAM to me?



[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: mark hunte on Feb 22, '08 10:21:57AM
Command Shift + I, does not send the email automatically. Which is what I think was the real intent here.

That being the case, then I would not want to go to mail.app, but stay in Safari,

Here is a slightly cleaned up version.

tell application "Safari"
	set thisPage to URL of document 1
	set theSubject to name of document 1
end tell
tell application "Mail"
	set theAddress to "Friends@mac.com"
	set theBody to "Hey, I thought you would be interested in this link:
" & thisPage
	tell application "Mail"
		set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
		set message signature of newMessage to signature "Cheers" -- Cheers being the name of an existing signature  already set up in Mail...
		tell newMessage
			set visible to false
			set sender to "yourFromMailAddress@mac.com"
			make new to recipient at end of to recipients with properties {address:theAddress}
			send
		end tell
	end tell
end tell
If you have more than one friend :-D , setting up a name selection should not be that hard.

---
mh

[ # ]

Fully automated, one-step sending of a URL from Safari
Authored by: nikoad on Feb 22, '08 10:45:35AM

For the past few years I have been using a Java scrip, I can't recall where I got it.

Create a new bookmark and copy the following into the location.

javascript:location.href='mailto:?SUBJECT='+document.title+'&BODY='+escape(location.href)

Name the bookmark something like "Send Link" and put it in your Bookmark Toolbar.
Works every time.



[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: mocharaia on Feb 22, '08 12:29:18PM

I use this javascript as well. The best part is it works on the iphone as well.



[ # ]
In-browser methods exist, too.
Authored by: ttt on Feb 22, '08 12:35:25PM
You can use the same JavaScript technique with a URL redirector to do the same thing without involving Mail at all. For example, http://mu.subsume.com/ makes it pretty trivial to "send" pages to an iPhone (or someone else, like the OP wanted).

[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: madmac33 on Feb 22, '08 04:19:03PM

Simply add the email address to the javascript comment from earlier reply and follow same instructions suggested;
- make it a bookmark on the Bar
- click when you want to send a page
- cmd + shift + d

javascript:location.href='mailto:joe.somebody@whatever.com?SUBJECT='+document.title+'&BODY='+escape(location.href)



[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: emaven on Feb 22, '08 05:04:39PM

javascript:location.href='mailto:somebody@mac.com?SUBJECT='+document.title+'&BODY='+document.title+'%5Cn%20%20%20%3C'+escape(location.href)+'%3E'

This puts the subject in the title, and again in the body of the email along with the URL surrounded with <>.
This is done in case the URL is too long and would break into several lines, which may render the link useless.

Just click send (or command-shift-D) in the mail program and you're done.

I have more than one friend, so I make several of these with each friends name.
Or I can use a group name that gets the individuals from my address book.
But if I have too many friends these bookmarks would take up too much room on my bookmark bar.
There would be no room for my other important bookmarks.

So put them all into a folder, and put the folder on the bookmarks bar.
Then just pick the one you want from the folder.


note:
The script used to put the subject on one line, and the URL on the next line by virtue of the %5Cn.
But that stopped working and I do not know why.
So I added several of %20 to separate the subject from the URL.



[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: mark hunte on Feb 23, '08 03:35:23AM

You can add the Javascript to each person Card in Address
Book. Use the Url Field. Then in Safari put the Address Book in the Book Marks Bar.
The Names of people with an Url Shows up, if its the Javascript Url it will run



---
mh



[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: smkolins on May 23, '08 10:26:00AM
any ideas on how to adapt a Ff3 option for people that use webmail functions instead of Mail.app?

See urls like http://fearthenoob.com/2008/05/23/gmail-mailto-links-in-firefox-3.php where you can tell Ff3 to take you to the url for your webmail. I'm trying to find something similar for Safari 3.

---
Possess a pure, kindly, and radiant heart!

[ # ]

Fully automated, one-step sending of a URL from Safari
Authored by: jaguarz on Feb 23, '08 08:24:09AM

What's the big deal...? [ Apple (cmd) + shift + i ] will create an email with the url of the current Safai window in the body

or

[ Apple (cmd) + i ] will create an email and embed the page contents (not just the url) in to an new email....

sure you have to press "send" but apple created Safai to do that... and if you figured how long it took to create this "time saving apple script" verses how long it takes to click "send"... i bet you spent more time writting the apple script.

no brainer... Apple + i



[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: mark hunte on Feb 23, '08 08:58:55AM

You have to also type the sender.


I think the javascript is a better way to go as you can add the sender/s.

Thinking about it, if you create a folder in the Bookmarks Menu. and add a javascript for each recipient you send pages to. You can then go to The keyboard Shortcuts in system prefs and add a safari application short cut to each using the Name of the bookmark. eg.


MarkMail (+shift+M)
JohnMail (+shift+J)

I spent 5 seconds on that thought, a 20 seconds on testing it.



---
mh



[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: mark hunte on Feb 23, '08 09:00:19AM

sender above should read recipient

---
mh



[ # ]
Fully automated, one-step sending of a URL from Safari
Authored by: chueewowee on Sep 21, '08 08:18:59AM
Here's a modified version that includes selected text as well as URL , as a quote from the page. I like it.

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

-- Get the current URL
tell application "Safari"
	activate
	set the clipboard to ""
	tell application "System Events" to keystroke "c" using command down
	set myCount to count (the clipboard)
	if myCount = 0 then
		display dialog "Oops, you forgot to select some text in Safari." & return & return & "Please select the text you want to include in your email and try again." buttons {"OK"} default button "OK"
		return
	end if
	set SelectedText to the clipboard
	set thisPage to do JavaScript "document.URL" in document 1
	set PageName to name of front document
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:"name@server.com", «class rdsn»:"FirstName LastName"}
		set the subject to PageName
		set the content to "Hey, I thought you would be interested in this link: 
" & thisPage & "
QUOTE:
" & SelectedText & "
--
Signature Here"
		
		
	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


[ # ]