[MacRuby-devel] Basic delayed email method

Cliff Rosson cliff.rosson at gmail.com
Tue Oct 23 21:42:35 PDT 2012


With Steve's help I think I have a working solution. Basically I'll run a
macruby script as a cron job which checks my drafts folder every 15 minutes.

time_range = ((Time.now - 150)..(Time.now + 300)
#I am not sure how much lag I can expect from the job. I would assume it
will do its work in only a few seconds but here I have given myself a few
minutes grace.

I'll create an draft email with the a tag in the subject line. "[SEND at 16:15]"
for example. When the appropriate time comes my script will build an
outgoing message for each draft with a time tag that matches the present
time_range. The tag will be removed from the subject and the message will
be sent. It will then delete the now expired draft message.

What do you guys think about this? This seems like the easiest way to get
delayed/automated emails configured in Apple Mail without much
sophistication. There are some limitations that could be fixed, like taking
date into account.

On Tue, Oct 23, 2012 at 11:56 AM, Steve Clarke <steve at sclarkes.me.uk> wrote:

> Re A)  I think it should be easy to transfer the content from draft to
> outgoing message.  Don't both use MailRichText?
>
> B) I think you'll be stuck with that problem.  As far as I can see you
> can't mutate an existing message into an outgoing message.
>
> Steve
>
> On 23 Oct 2012, at 19:05, Cliff Rosson <cliff.rosson at gmail.com> wrote:
>
> Yea putsing methods(true,true).sort is pretty useful. Below is what I have
> compiled so far.
>
> framework "ScriptingBridge"
>
>
>>  @mail = SBApplication.applicationWithBundleIdentifier("com.apple.mail")
>> @my_account = @mail.accounts.select { |account| account.name ==
>> "MyAccount" }.first
>> @drafts_folder = @my_account.mailboxes.select { |mailbox| mailbox.name== "Drafts" }.first
>> @draft = @drafts_folder.messages.first
>>
>
>
> def send_message(message)
>>   props = {}
>>
>>   props['subject'] = message.subject
>>   props['sender'] = message.sender
>>   #props['content'] = message.content
>>
>>
>>   outgoing_msg = @mail.classForScriptingClass('outgoing
>> message').alloc.initWithProperties(props)
>> @mail.outgoingMessages.addObject(outgoing_msg)
>>   recipient =  @mail.classForScriptingClass('to
>> recipient').alloc.initWithProperties({'address'=>message.recipients.first.address})
>>   outgoing_msg.toRecipients.addObject(recipient)
>>
>>   outgoing_msg.send
>>
>> end
>> send_message(@draft)
>
>
> *Note I used instance variables so I could play with these objects in
> macirb. If you were wondering...
>
> The code above works. I get the email. Two issues however.
>
> A)
> I can't figure out how to pull the text contents of my @draft.contents
> message. Presumably because it is a MailRichText class and not a simple
> string object. If only somehow I could attach this contents to the outgoing
> message to preserve the body. What would be even better is to simply create
> my outgoing message with something like InitWithDraft so as to use a
> drafted email already created. I suspect this will require further research
> from me.
>
> @draft.content
> => <MailRichText @0x1370760: content of MailMessage 0 of MailMailbox 19 of
> MailAccount 0 of application "Mail" (1845)>
>
> B)
> The other issue is since I am not using my existing drafted email creating
> this outgoing message actually makes a NEW draft in my Draft folder. It
> looks like I would have to go and manually delete the draft that I am
> attempting to copy in the method above. I believe there must be an easier
> way to do this. This comes back to what I was talking about above by
> creating the outgoing message from a draft. I guess I'll just have to do
> some research to figure that out.
>
> Thanks Steve for your help!
>
>
>
>
> On Tue, Oct 23, 2012 at 10:12 AM, Steve Clarke <steve at sclarkes.me.uk>wrote:
>
>> You need to use the ScriptingBridge documentation in Xcode - which means
>> that you need to spend some time understanding Objective C.  I don't know
>> it well but enough to translate examples into Macruby.
>>
>> I found Matt Aimonetti's book very helpful when I was starting off. It
>> doesn't say a lot about ScriptingBridge per se, but in the end SB is just
>> another framework you can use from Macruby.
>>
>> It's worth looking back at the Macruby archives because Matt wrote some
>> very helpful stuff about using SB.  One tip I recall is that you can see
>> what methods are available on an object in Macruby by using
>> obj.methods(true,true).  This gives tons of stuff but critically it shows
>> both the Macruby methods AND the Objective C methods.  With SB it's the
>> latter group that are of real interest.
>>
>> Steve
>>
>> On 23 Oct 2012, at 17:52, Cliff Rosson <cliff.rosson at gmail.com> wrote:
>>
>> Perfect! How did you figure all of this out. Are there some documents
>> that explain when it is appropriate to use things like
>> "classForScriptingClass" etc...?
>>
>> On Tue, Oct 23, 2012 at 9:49 AM, Steve Clarke <steve at sclarkes.me.uk>wrote:
>>
>>
>>
>> --
>> http://about.me/cliffrosson
>> vizualize.me/cliffrosson
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>>
>>
>>
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>>
>>
>
>
> --
> http://about.me/cliffrosson
> vizualize.me/cliffrosson
>  _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>
>
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>
>


-- 
http://about.me/cliffrosson
vizualize.me/cliffrosson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20121023/e7076a1e/attachment.html>


More information about the MacRuby-devel mailing list