TIP: Email a URL using Applescript
I find stuff all the time on the internet that I like to share with other people. In an attempt at making that easier, here's an applescript that I found on the apple site and modified it a little bit to do just what I wanted. This script only works with apple mail.
If you haven't enabled the script menu, do so by running Applications/AppleScript/Install Script Menu. You will see the new applescript menu appear by the time at the top of your screen.
Open the script editor and paste this into it...
tell application "Safari"
set this_URL to the URL of document 1
set window_title to the name of document 1
end tell
tell application "Mail"
activate
set this_message to make new outgoing message with properties {visible:true, subject:window_title, content:("Check this out: <" & this_URL & ">")}
end tell
Save your new script with a title like 'Email this URL' and drop it in your Library/Scripts/Safari folder. If there is no Safari folder in there, create one. Now when your in safari, choose your new script from the scripts menu and a new email will be created with the page title as the email subject and a link to the page in the body of the email. Very nice.
It might seem like a lot of work at first but once you get the hang of applescript, there is a lot more that you can do with it. It's well worth knowing.


2 Comments:
Hey, nice tip I actually came across this while searching for a way to automatically SEND the email that was created through Applescript.
In regards to your script, the problem is that the new email is waiting for you to hit the Send button to actually send the email. Is there a script step that automatically sends the email once it's created?
I am trying to setup a script that sends an email out from a headless server. When my script would run, there would be nobody to hit the Send button.
Aye, I figured it out. I was trying to use the command "send message", but really, the command would be "send this_message" where "this_message" is the name of the email according to the script.
So, if you wanted to automatically send that hyperlink without reviewing the email first, you would just add the line "send this_message" (without quotes) on its own line just before the end tell line.
Post a Comment
<< Home