Grab URL, Paste Into email

Hi folks.

I want to have a script that grabs the current url in Safari (top window/tab) and copy that to paste in the current location in an email I am writing.

This is what I have so far:

tell application "Safari" to set myLoc to the URL of document 1
set the clipboard to myLoc
tell application "Mail" to activate
paste

Everything copies, but it doesn’t paste. I might have some text in the body of the current email. The content isn’t updating. I’m not sure how to append the current clipboard into a string, then paste that into the content. Is that just a:

set the content of myWindow to myContent

I’ve tried all this, and nothing works nor compiles. Any help appreciated.

Cheers

This might be better answered in the “AppleScript | OS X” forum.

OK, thank you. I am assuming you have moved it.

So here’s my update:

The only thing standing in my way now is to somehow have a current new outgoing message that’s created, shoved into an object. Most examples have this in the code, like this:

set myM to (make new outgoing message with properties {content: myContent})

Unfortunately I won’t be using that. I have a new email with the recipent (To:), and the subject already filled in, and I am assuming some text. What I want to do is add the current url.

Yes I can copy, or drag. That’s a hassle. I live in Launchbar, so keyboard is where my hands are, and I want to launch this instantly and have the url show up where the cursor is.

So how do I get a current email window into an instance? Is this an outgoing message, or a window, or a document? Mail.app can be a bit confusing.

Cheers

Found it:

tell application "Safari" to set myLoc to the URL of document 1
set the clipboard to myLoc
tell application "Mail" to activate
tell application "System Events" to tell process "Mail" -- GUI Scripting
	keystroke "v" using command down -- ⌘V to paste the URL
end tell

Very nice. Respects signatures as well. Inserts right where I want it.

Cheers

I know this is an old post but for what it is worth command+shift+I sends a link in an email of the current page. Years ago it use to be just command+I (at least since 2005 when I first discovered it in Safari). Command+I depending on your version of Safari will send a HTML copy of the webpage or in Safari 6 will send a PDF of the webpage.

Hi there.

I use it all the time. The issue with this is that you have to be in Safari to use this trick. If you are in Mail.app, then it’s useless.

I also wanted to copy the current URL for Messages as well.

Cheers

Oh gotcha very nice, makes sense.