Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Old 01-13-2013, 10:32 AM   #1
ArchMan11
Prospect
 
Join Date: Apr 2011
Posts: 4
Using Applescript to Send Gmail Efficiently

I am not familiar with scripting to any degree, so I would appreciate any help I can get with what seemingly should be an easy task.

What I'd like to be able to do, ideally, is to make it very easy to send the URL of any web page I might be on to my brother Jon via Gmail in Firefox, with as few steps as possible.

So the scenario is this: Let's say I'm on Apple's homepage. I would like to be able to do something simple like Right click, which would pop up an option such as "Send Current URL to My Brother Jon". I select that option, and an email, via my Gmail account, is automatically sent containing the URL to my brother Jon.

Is this a ridiculous thing to want?
ArchMan11 is offline   Reply With Quote
Old 01-13-2013, 12:10 PM   #2
benwiggy
League Commissioner
 
Join Date: Aug 2006
Location: London
Posts: 5,785
It's certainly possible with Safari, as you can do this fairly easily in Automator -- no coding required.
Open Automator and create a new Service. (Services will be accessible on a right-click from the web page.)
There's a "Get Current Webpage from Safari" action; and then just add a "New Mail Message" action. You can even specify your brother's email address and a Subject.
You'll still have to click "Send" yourself, though.

Whether you can do something similar in FireFox will depend on its Automator and AppleScript support. A quick Google suggests it's not great. I doubt it has Automator support at all.

Last edited by benwiggy; 01-13-2013 at 12:23 PM.
benwiggy is online now   Reply With Quote
Old 01-13-2013, 12:47 PM   #3
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,823
There is the issue that benwiggy mentioned, whereby Firefox doesn't have built-in support for AppleScript. On top of that, you're using Gmail in Firefox, and scripting actions on any web page is difficult.

If you were using the Safari and Mail applications, this could easily be done by making a Service which uses this AppleScript:

Code:
set theSubject to "Cool Link"

tell application "Safari"
	set theURL to URL of current tab of window 1
end tell
tell application "Mail"
	activate
	set theNewMessage to make new outgoing message with properties {subject:theSubject, content:return & (theURL), visible:false}
	tell theNewMessage
		make new to recipient at end of to recipients with properties {address:"BrotherJon@gmail.com"}
		send theNewMessage
	end tell
end tell
NaOH is offline   Reply With Quote
Old 01-13-2013, 01:21 PM   #4
ArchMan11
Prospect
 
Join Date: Apr 2011
Posts: 4
Thanks to Both of You

I appreciate having two Hall of Famers' input. I've got nothing against Safari, so that's no problem. I've never bothered to set up Mail, but I've no doubt that it's a no brainer.

So, it will be fun to try what you have suggested. I'll let you know if I hit any snags and how things go.

Thanks again for your help. This is a fantastic forum, there is always someone like you guys who knows what he's talking about and is willing to share it.

A.
ArchMan11 is offline   Reply With Quote
Old 01-13-2013, 01:27 PM   #5
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,823
Many users of Gmail in standalone email applications (like Apple Mail) don't like by how Gmail presents itself in that setup. If you find yourself feeling similarly, have a look at this long but thorough and informative article on how much of Gmail in Mail can be modified.

http://tidbits.com/article/10253
NaOH is offline   Reply With Quote
Old 01-13-2013, 01:46 PM   #6
NaOH
Hall of Famer
 
Join Date: Dec 2007
Posts: 3,823
This is an alternative script I already have. Launched from within Safari, it will ask you to provide a subject line, allow you to add a message to be included with the URL of the current Safari tab/window, and it will then show a little preview of the message, at which point you can send it or save it as a draft. All of this will happen without Mail coming to the front.

If you have similar emailing behavior with other people, this could be modified to allow you to choose who will get the email. So, prior to adding a subject line or message, you'd be asked if the current Safari page should be used in an email to your brother, sister, cousin, or aunt.

Code:
set theAddress to "BrotherJon@Gmail.com"

tell application "Safari"
	set theURL to URL of current tab of window 1
	set the clipboard to theURL
end tell

-- Prompt for message subject
tell application "System Events"
	activate
	set theResult to display dialog "Subjectů" default answer "" buttons {"Cancel", "Next"} default button 2
	set theSubject to text returned of theResult
	
	-- Prompt for message body
	set theResult to display dialog "Message..." default answer "" buttons {"Cancel", "Preview"} default button 2
	set theBody to text returned of theResult
end tell

tell application "System Events"
	set theResult to display dialog theAddress & "
" & "
" & theSubject & "
" & "
" & "
" & theBody & "
" & "
" & (the clipboard) buttons {"Cancel", "Save As Draft", "Send"} default button 3
end tell

if button returned of theResult is "Send" then
	tell application "Mail"
		set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return & (the clipboard)}
		tell newMessage
			make new to recipient at end of to recipients with properties {address:theAddress}
			send
		end tell
	end tell
end if

if button returned of theResult is "Save As Draft" then
	tell application "Mail"
		set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return & (the clipboard)}
		tell newMessage
			make new to recipient at end of to recipients with properties {address:theAddress}
			save
		end tell
	end tell
end if

end
NaOH is offline   Reply With Quote
Old 01-13-2013, 04:46 PM   #7
ArchMan11
Prospect
 
Join Date: Apr 2011
Posts: 4
Thanks Again

Thanks again for the help. I'm going to give it a try and I'll let you know how it goes.

A.
ArchMan11 is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:27 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.