Create a Dock Shortcut for a drafted email?!


Recommended Posts

Ok, for my MoBlog, i simply drag an image into the body of the email, add a subject, and send it to a specific email. I'm trying to make it easier for myself... Just out curiosity as much as anything. Basically, I wanted to be able to drag a pre-drafted email (the email field already filled in) to the dock. Ideally so that I could maybe even drop the image onto it, for it to attach (But that may be asking a bit much) ... Is this at all possible? If not obviously, maybe via AppleScript?

It would be really cool if anyone knew anything about it! :)

Link to comment
Share on other sites

check out the mail scripting dictionary (drag drop mail onto applescript editor).

You can create an application that fills out a message and has it ready to send in mail. if you want you could even make it a droplet: drag/drop image onto icon and click send.

Link to comment
Share on other sites

file:///Library/Scripts/Mail%20Scripts/

Thanks for the reply Evn ... I expected you to know a thing or two about this! Wow, i did what you said, and its gave me one big ass list of stuff! Only trouble is, it looks good, i wouldn't have a clue how to start it! I'll have to see if i can find some sample scripts so i can try to work out how to add stuff, etc etc... any help would be appreciated. :)

Edit: Ok i used a default one i found in the included scripts on my mac. thing is, it seems REALLY complicated to me, all i really want is a script that has:

Drag image to icon to attach (if poss)

to field already filled out

...Maybe then if poss the 'subject line' field set as the active text input selection?!

God knows how tho!

Link to comment
Share on other sites

The scripting dictionary has two 'sections' worth mentioning: Classes and Commands.

Commands are things you can tell the application to do (inside a tell block). For example mail has 'check for new mail' as a command' and 'move'

check for new mail is a function in and of itself: it doesn't make sense to check for new mail in a specific message or something so you can just use it:

tell application "Mail"
  check for new mail
end tell

on the other hand the 'move' command doesn't make any sense unless you are talking about a message. if you were talking to me you would say "move the message <X> to <y>"

Tell application "mail"
  move the first message of inbox to trash
end tell

Classes on the other hand are the objects and data inside the application. Mail has a few but they aren't very hard to figure out what they refer to:

account is an email account so it would have properties like what you see in preferences - accounts: address, server, full name...

message viewer is the mail window so it has properties like the selected mailbox (icons in the drawer), selected message, and whether or not the preview pane is visible.

if you combine the 'commands' with 'classes' you can tell mail what you want to do, to what you want to do it too.

ie:

tell application "mail"
  check for new mail
  set TOTAL to unread count of inbox
  if TOTAL &gt; 0 then set NEWEST_MESSAGE to first message of inbox
  set WHO_SENT_IT to reply to of NEWEST_MESSAGE

  display dialog "New message from: " &amp; WHOE_SENT_IT &amp; "."
end tell

You can see the commands pretty clear: "check for new mail", "set" <x> "to" <y> "display dialog", etc because they're what happens. the classes are the things that those events happened to:

'first message' was selected out of 'inbox' then reply to was selected from that first message.

It might be a little hard to get going with if you don't have any experience with programming but if you would like to know more the O'reilly books are excellent.

Anyway, I'm going to poor a cup of tea and have some breakfast. I'll bash out an example that does what you want later on unless you find something sooner.

Link to comment
Share on other sites

well, at first I had this huge applescript post, but then i thought there must be an easier way to do this, so I made a mail-to url. then I thought "i wonder if..." and I came up with this amazing one line beast!

do shell script "open mailto:whereisthis@going.com?subject=Subject%20Goes%20Here\\&amp;body=your%20message%20goes%20here"

replace "whereisthis@going.com" to the address it's going to

replace "Subject%20Goes%20Here" with the subject you want.

replace "your%20message%20goes%20here" with the message you want.

In case you haven't noticed, you have to replace all of your spaces with "%20".

double-click on the icon, and you'll have a message ready to send. I've attached an example program. drag-drop it onto the script-editor icon to view/change the code.

EDIT: Neowin doesn't like .app attachments - she mangles them.

Also, sorry for bumping the post.

Edited by the evn show
Link to comment
Share on other sites

Wow man! thanks I didn't realize you'd replied!

Thats nice and simple too! the only thing i would like to add, would be to have it work with some attachments or something. Each mail i compose to this 'person' will always have an attached jpg. My whole idea of this, was to make it as simple as poss (Not that it was difficult, but still...) I can always drag the image, and drop it to the body, but I figured their might be something I could do to make it more automated. Would you know how, for example I could execute that code you provided, aswell as maybe ask for an attachment?

Thanks alot for your time tho mate, you've been MORE than helpful! :)

Link to comment
Share on other sites

I adapted the New Mail script, cut out half the questioning... Here's how it finished up.

-- Repeat this loop until the text entered has been changed from the default example text.
repeat
	set theResult to "Me - TextAmerica"
	set theName to theResult
	if (theName does not start with "Example:") then
 ?exit repeat
	end if
end repeat

-- Repeat this loop until the text entered has been changed from the default example text.
-- Email address validation could be done at this point.
repeat
	set theResult to "neyo@tamw.com"
	set theAddress to theResult
	if (theAddress does not start with "Example:") then
 ?exit repeat
	end if
end repeat



-- Prompt for whether an attachment is desired. If so, prompt for the location of the file.
set theResult to display dialog "Would you like to attach some files to this message?" buttons {"Yes", "No"} default button 1
set wantsAttachment to button returned of theResult
if wantsAttachment is equal to "Yes" then
	set theAttachment to choose file
end if

-- Prompt for message subject
set theResult to display dialog "What would you like the subject of the message to be?" default answer "..."
set theSubject to text returned of theResult

-- Prompt for message body
set theResult to ""
set theBody to theResult


-- Prompt the user to select which account to send this message from.
set theResult to "neyo_x@yahoo.co.uk"
if theResult is not equal to false then
	set theSender to theResult
	tell application "Mail"
 ?-- Properties can be specified in a record when creating the message or
 ?-- afterwards by setting individual property values.
 ?set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody &amp; return &amp; return}
 ?tell newMessage
 ?	-- Default is false. Determines whether the compose window will
 ?	-- show on the screen or whether it will happen in the background.
 ?	set visible to true
 ?	set sender to theSender
 ?	make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
 ?	tell content
 ? ?if (wantsAttachment is equal to "Yes") then
 ? ?	-- Position must be specified for attachments
 ? ?	make new attachment with properties {file name:theAttachment} at after the last paragraph
 ? ?end if
 ?	end tell
 ?end tell
 ?-- Bring the new compose window to the foreground, in all its glory
 ?activate
	end tell
end if

Ok, now i know there's a tonne of excess code in there, but I am pretty happy with that. I am curious tho, is it possible to just set a list of properties...

Like Subject = " yayya

Content =

and then refer to them later on? I hope that makes sense. It was just that having this (just to set the name) seemed a lot...

repeat
	set theResult to "Me - TextAmerica"
	set theName to theResult
	if (theName does not start with "Example:") then
 ?exit repeat
	end if
end repeat

Could I just do...

Set theName to "Me - TextAmerica"

Set theAddress to "neyo@yaaya.co.uk"

...then refer them to later on, when its grabbing all the info, to compose the mail?

Link to comment
Share on other sites

Ok, i tried it myself, this is much better...

set theName to "Me"
set theAddress to "neyo_x@yahoo.co.uk"
set theSubject to "test..."
set theResult to display dialog "Would you like to attach some files to this message?" buttons {"Yes", "No"} default button 1
set wantsAttachment to button returned of theResult
if wantsAttachment is equal to "Yes" then
	set theAttachment to choose file
end if
set theSender to "neyo_x@yahoo.co.uk"
tell application "Mail"
	set newMessage to make new outgoing message with properties {subject:theSubject}
	tell newMessage
 ?set visible to true
 ?set sender to theSender
 ?make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
 ?tell content
 ?	if (wantsAttachment is equal to "Yes") then
 ? ?-- Position must be specified for attachments
 ? ?make new attachment with properties {file name:theAttachment} at after the last paragraph
 ?	end if
 ?end tell
	end tell
	activate
end tell

That is pretty much all I want. Colin, if you know how I can have the 'Subject Line' Field Highlighted, after it composes the email, that'd be great... thats the ONLY thing I'd like to:)hange... :)

Thanks for introducing me to this stuf:)tho! :) Worth learning I guess...

Edit: So it'll probably invoke this... but i am not sur:(how! :( (thanks for the hookup Josh)

tell window "user information"

    set first responder to text field "user name"

end tell

Edited by ~~NeYo~~
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.