Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Steve Clarke
Hi Cliff,

I struggled with this too.  I'm afraid I can't remember all the details, but I 
think that one key point is that you need to have an "outgoing message" to 
respond to send.  You may need to add your draft message to the mail apps 
"outgoing messages" before it can be sent.  Try something like

mail.outgoingMessages.addObject(draft)

Steve

On 23 Oct 2012, at 07:06, Cliff Rosson  wrote:

> 
> My drafts folder has 1 message in it ready to be sent.
> 
> mail = SBApplication.applicationWithBundleIdentifier("com.apple.mail")
> my_account = mail.accounts.select { |account| account.name == "MyAccountName" 
> }.first
> drafts_folder = my_account.mailboxes.select { |mailbox| mailbox.name == 
> "Drafts" }.first
> draft = drafts_folder.messages.first
> 
> I need to use the send method somehow. I think I need to make a new 
> MailOutgoingMessage but I would like to make this message based on my already 
> existing draft message.
> 
> Any know how this is done?

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo/macruby-devel


Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Steve Clarke
Just had a closer look at what I did with sending mail and I think my earlier 
reply was probably  wrong, or at least not helpful.  I think the difficulty 
arises because there are some things that ScriptingBridge is unable to do.  I 
could not find a way to create an outgoing message with ScriptingBridge and I 
had to resort to running a trivial applescript (using NSAppleScript 
executeAndReturnError)  to do the job for me.  If anyone knows a better way I'd 
be delighted to hear about it! 

I created the applescript from a template that I modified in my code before I 
executed it.  I guess Cliff could adopt a similar approach to copy subject, 
content etc from his draft.

Here's the template.  The %HTML% and %SUBJECT% are placeholders that get 
replaced by the actual values before execution.

=
tell application "Mail"
activate
set htmlMsg to "%HTML%"
set subjecta to "%SUBJECT%"
set theMsg to make new outgoing message with properties ¬
{subject:subjecta, html content:htmlMsg & return & return, 
content:""}
end tell
=

Steve

On 23 Oct 2012, at 07:06, Cliff Rosson  wrote:

> So playing around a little with this I was able to browse and find messages 
> via macruby. On the other hand I cannot figure out how to send a drafted 
> email. Here is what I have so far.
> 
> My drafts folder has 1 message in it ready to be sent.
> 
> mail = SBApplication.applicationWithBundleIdentifier("com.apple.mail")
> my_account = mail.accounts.select { |account| account.name == "MyAccountName" 
> }.first
> drafts_folder = my_account.mailboxes.select { |mailbox| mailbox.name == 
> "Drafts" }.first
> draft = drafts_folder.messages.first
> 
> I need to use the send method somehow. I think I need to make a new 
> MailOutgoingMessage but I would like to make this message based on my already 
> existing draft message.
> 
> Any know how this is done?
> 
> I had hoped it would have been as simple as draft.send. :)
> 
> 
> On Sat, Oct 20, 2012 at 2:14 PM, Mark Rada  wrote:
> Hi Rob,
> 
> I think Colin answered this fairly well. Personally, I prefer to use GCD when 
> available because I find the API simpler and GCD stuff works with or without 
> run loops.
> 
> --
> Mark
> 
> 
> On 2012-10-20, at 2:40 PM, Robert Carl Rice  wrote:
> 
> > Hi Mark,
> >
> > I use NSTimer a lot in my apps. What is the advantage of using GCD API?
> >
> > There is an excellent tutorial on the web for specifically for setting up 
> > ScriptingBridge for Apple Mail but I forget where I saw it. On warning; if 
> > you set up ScriptingBridge for Apple Mail don't try to take a snapshot in 
> > Xcode 4. Xcode will follow the link to mail and include all of your 
> > mailboxes in the snapshot. I don't know if there is a way to stop this 
> > behavior.
> >
> > Bob Rice
> >
> > On Oct 19, 2012, at 6:50 PM, Mark Rada  wrote:
> >
> >> Busy looping for an hour would be really bad. I assume you would have a 
> >> sleep in there, but then you're still polling.
> >>
> >> If you are using MacRuby, looking at the GCD API would be a good idea. You 
> >> could do something like this:
> >>
> >> def schedule_email q
> >>   q.after(3600) do
> >>   # Send email
> >>   schedule_email q
> >>   end
> >> end
> >>
> >> schedule_email Dispatch::Queue.new("com.rosson.delayed.email")
> >>
> >> NSRunLoop.currentRunLoop.run
> >>
> >>
> >>
> >> As for actually sending emails, if you want to have things go through 
> >> Apple Mail you could use the ScriptingBridge framework which has a few 
> >> tutorials online (but for iTunes):
> >>
> >> http://arstechnica.com/apple/2011/09/tutorial-os-x-automation-with-macruby-and-the-scripting-bridge/
> >>
> >> AXElements is another option that I am biased in favour of; but it may not 
> >> be passive enough for your requirements.
> >>
> >> HTH,
> >>  Mark
> >>
> >>
> >> On 2012-10-19, at 6:12 PM, Cliff Rosson  wrote:
> >>
> >>> Hi Everyone,
> >>>
> >>> I am fairly new to macruby and am having trouble finding some basic 
> >>> documentation to help me out. I would like to write a simple app that 
> >>> sends a delayed email based on Time from mac mail.
> >>>
> >>> I am thinking of something like this,
> >>>
> >>> time = Time.now + 3600
> >>> while true
> >>> case time
> >>> when Time.now
> >>>   #Send email
> >>> end
> >>> end
> >>>
> >>> Being able to respond to certain emails or send an email from a draft 
> >>> would be a huge benefit. Can anyone point me in the write direction to 
> >>> accomplish this? I am decently proficient in ruby but don't know where to 
> >>> start with MacRuby.
> >>>
> >>> Thanks everyone
> >>>
> >>> ___
> >>> MacRuby-devel mailing list
> >>> [email protected]
> >>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
> >>
> >> ___
> >> MacRuby-devel mailing list
> >> [email protected]
> >

Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Mark Rada
Hi Cliff,

Did you manage to find the SBSendEmail sample code:

https://developer.apple.com/library/mac/#samplecode/SBSendEmail/Introduction/Intro.html

The sample they have looks a bit different from what you have. I haven't tried 
it out myself, but their documentation seems quite thorough and was updated 
only a year ago.





On 2012-10-23, at 5:28 AM, Steve Clarke  wrote:

> Just had a closer look at what I did with sending mail and I think my earlier 
> reply was probably  wrong, or at least not helpful.  I think the difficulty 
> arises because there are some things that ScriptingBridge is unable to do.  I 
> could not find a way to create an outgoing message with ScriptingBridge and I 
> had to resort to running a trivial applescript (using NSAppleScript 
> executeAndReturnError)  to do the job for me.  If anyone knows a better way 
> I'd be delighted to hear about it! 
> 
> I created the applescript from a template that I modified in my code before I 
> executed it.  I guess Cliff could adopt a similar approach to copy subject, 
> content etc from his draft.
> 
> Here's the template.  The %HTML% and %SUBJECT% are placeholders that get 
> replaced by the actual values before execution.
> 
> =
> tell application "Mail"
>   activate
>   set htmlMsg to "%HTML%"
>   set subjecta to "%SUBJECT%"
>   set theMsg to make new outgoing message with properties ¬
>   {subject:subjecta, html content:htmlMsg & return & return, 
> content:""}
> end tell
> =
> 
> Steve
> 
> On 23 Oct 2012, at 07:06, Cliff Rosson  wrote:
> 
>> So playing around a little with this I was able to browse and find messages 
>> via macruby. On the other hand I cannot figure out how to send a drafted 
>> email. Here is what I have so far.
>> 
>> My drafts folder has 1 message in it ready to be sent.
>> 
>> mail = SBApplication.applicationWithBundleIdentifier("com.apple.mail")
>> my_account = mail.accounts.select { |account| account.name == 
>> "MyAccountName" }.first
>> drafts_folder = my_account.mailboxes.select { |mailbox| mailbox.name == 
>> "Drafts" }.first
>> draft = drafts_folder.messages.first
>> 
>> I need to use the send method somehow. I think I need to make a new 
>> MailOutgoingMessage but I would like to make this message based on my 
>> already existing draft message.
>> 
>> Any know how this is done?
>> 
>> I had hoped it would have been as simple as draft.send. :)
>> 
>> 
>> On Sat, Oct 20, 2012 at 2:14 PM, Mark Rada  wrote:
>> Hi Rob,
>> 
>> I think Colin answered this fairly well. Personally, I prefer to use GCD 
>> when available because I find the API simpler and GCD stuff works with or 
>> without run loops.
>> 
>> --
>> Mark
>> 
>> 
>> On 2012-10-20, at 2:40 PM, Robert Carl Rice  wrote:
>> 
>> > Hi Mark,
>> >
>> > I use NSTimer a lot in my apps. What is the advantage of using GCD API?
>> >
>> > There is an excellent tutorial on the web for specifically for setting up 
>> > ScriptingBridge for Apple Mail but I forget where I saw it. On warning; if 
>> > you set up ScriptingBridge for Apple Mail don't try to take a snapshot in 
>> > Xcode 4. Xcode will follow the link to mail and include all of your 
>> > mailboxes in the snapshot. I don't know if there is a way to stop this 
>> > behavior.
>> >
>> > Bob Rice
>> >
>> > On Oct 19, 2012, at 6:50 PM, Mark Rada  wrote:
>> >
>> >> Busy looping for an hour would be really bad. I assume you would have a 
>> >> sleep in there, but then you're still polling.
>> >>
>> >> If you are using MacRuby, looking at the GCD API would be a good idea. 
>> >> You could do something like this:
>> >>
>> >> def schedule_email q
>> >>   q.after(3600) do
>> >>   # Send email
>> >>   schedule_email q
>> >>   end
>> >> end
>> >>
>> >> schedule_email Dispatch::Queue.new("com.rosson.delayed.email")
>> >>
>> >> NSRunLoop.currentRunLoop.run
>> >>
>> >>
>> >>
>> >> As for actually sending emails, if you want to have things go through 
>> >> Apple Mail you could use the ScriptingBridge framework which has a few 
>> >> tutorials online (but for iTunes):
>> >>
>> >> http://arstechnica.com/apple/2011/09/tutorial-os-x-automation-with-macruby-and-the-scripting-bridge/
>> >>
>> >> AXElements is another option that I am biased in favour of; but it may 
>> >> not be passive enough for your requirements.
>> >>
>> >> HTH,
>> >>  Mark
>> >>
>> >>
>> >> On 2012-10-19, at 6:12 PM, Cliff Rosson  wrote:
>> >>
>> >>> Hi Everyone,
>> >>>
>> >>> I am fairly new to macruby and am having trouble finding some basic 
>> >>> documentation to help me out. I would like to write a simple app that 
>> >>> sends a delayed email based on Time from mac mail.
>> >>>
>> >>> I am thinking of something like this,
>> >>>
>> >>> time = Time.now + 3600
>> >>> while true
>> >>> case time
>> >>> when Time.now
>> >>>   #Send email
>> >>> end
>> >>> end
>> >>>
>> >>> Being able to respond to certain emails or send an email from a draft 
>> >>> would 

Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Steve Clarke
Hi,

I got something similar working for a plain text email but there are additional 
requirements for HTML emails (which I needed), and I couldn't persuade SB to 
accept  html content.  I should have made that clear in my previous note.  If 
anyone has an example for HTML email with SB it would be great to see it.

Just taken a closer look at the scripting dictionary for mail and it looks like 
the "html content" property isn't documented - so who knows how I found it in 
the first place!  I just checked it out and it still works but obviously can't 
be relied on.  

Apologies for the red herring.  It looks as if there is no supported way to 
send html email using ScriptingBridge.

Steve

On 23 Oct 2012, at 15:52, Mark Rada  wrote:

> Hi Cliff,
> 
> Did you manage to find the SBSendEmail sample code:
> 
> https://developer.apple.com/library/mac/#samplecode/SBSendEmail/Introduction/Intro.html
> 
> The sample they have looks a bit different from what you have. I haven't 
> tried it out myself, but their documentation seems quite thorough and was 
> updated only a year ago.
> 
> 
> 
> 
> 
> On 2012-10-23, at 5:28 AM, Steve Clarke  wrote:
> 
>> Just had a closer look at what I did with sending mail and I think my 
>> earlier reply was probably  wrong, or at least not helpful.  I think the 
>> difficulty arises because there are some things that ScriptingBridge is 
>> unable to do.  I could not find a way to create an outgoing message with 
>> ScriptingBridge and I had to resort to running a trivial applescript (using 
>> NSAppleScript executeAndReturnError)  to do the job for me.  If anyone knows 
>> a better way I'd be delighted to hear about it! 
>> 
>> I created the applescript from a template that I modified in my code before 
>> I executed it.  I guess Cliff could adopt a similar approach to copy 
>> subject, content etc from his draft.
>> 
>> Here's the template.  The %HTML% and %SUBJECT% are placeholders that get 
>> replaced by the actual values before execution.
>> 
>> =
>> tell application "Mail"
>>  activate
>>  set htmlMsg to "%HTML%"
>>  set subjecta to "%SUBJECT%"
>>  set theMsg to make new outgoing message with properties ¬
>>  {subject:subjecta, html content:htmlMsg & return & return, 
>> content:""}
>> end tell
>> =
>> 
>> Steve
>> 
>> On 23 Oct 2012, at 07:06, Cliff Rosson  wrote:
>> 
>>> So playing around a little with this I was able to browse and find messages 
>>> via macruby. On the other hand I cannot figure out how to send a drafted 
>>> email. Here is what I have so far.
>>> 
>>> My drafts folder has 1 message in it ready to be sent.
>>> 
>>> mail = SBApplication.applicationWithBundleIdentifier("com.apple.mail")
>>> my_account = mail.accounts.select { |account| account.name == 
>>> "MyAccountName" }.first
>>> drafts_folder = my_account.mailboxes.select { |mailbox| mailbox.name == 
>>> "Drafts" }.first
>>> draft = drafts_folder.messages.first
>>> 
>>> I need to use the send method somehow. I think I need to make a new 
>>> MailOutgoingMessage but I would like to make this message based on my 
>>> already existing draft message.
>>> 
>>> Any know how this is done?
>>> 
>>> I had hoped it would have been as simple as draft.send. :)
>>> 
>>> 
>>> On Sat, Oct 20, 2012 at 2:14 PM, Mark Rada  wrote:
>>> Hi Rob,
>>> 
>>> I think Colin answered this fairly well. Personally, I prefer to use GCD 
>>> when available because I find the API simpler and GCD stuff works with or 
>>> without run loops.
>>> 
>>> --
>>> Mark
>>> 
>>> 
>>> On 2012-10-20, at 2:40 PM, Robert Carl Rice  wrote:
>>> 
>>> > Hi Mark,
>>> >
>>> > I use NSTimer a lot in my apps. What is the advantage of using GCD API?
>>> >
>>> > There is an excellent tutorial on the web for specifically for setting up 
>>> > ScriptingBridge for Apple Mail but I forget where I saw it. On warning; 
>>> > if you set up ScriptingBridge for Apple Mail don't try to take a snapshot 
>>> > in Xcode 4. Xcode will follow the link to mail and include all of your 
>>> > mailboxes in the snapshot. I don't know if there is a way to stop this 
>>> > behavior.
>>> >
>>> > Bob Rice
>>> >
>>> > On Oct 19, 2012, at 6:50 PM, Mark Rada  wrote:
>>> >
>>> >> Busy looping for an hour would be really bad. I assume you would have a 
>>> >> sleep in there, but then you're still polling.
>>> >>
>>> >> If you are using MacRuby, looking at the GCD API would be a good idea. 
>>> >> You could do something like this:
>>> >>
>>> >> def schedule_email q
>>> >>   q.after(3600) do
>>> >>   # Send email
>>> >>   schedule_email q
>>> >>   end
>>> >> end
>>> >>
>>> >> schedule_email Dispatch::Queue.new("com.rosson.delayed.email")
>>> >>
>>> >> NSRunLoop.currentRunLoop.run
>>> >>
>>> >>
>>> >>
>>> >> As for actually sending emails, if you want to have things go through 
>>> >> Apple Mail you could use the ScriptingBridge framework which has a few 
>>> >> tutorials online (but for iTunes):
>>> >

Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Cliff Rosson
Steve how did you get it working with the plain text. Below is the code I
think that is relevant in the SBS program.

- (IBAction)sendEmailMessage:(id)sender {
> /* create a Scripting Bridge object for talking to the Mail application */
> MailApplication *mail = [SBApplication applicationWithBundleIdentifier:
> @"com.apple.Mail"];
>
> /* set ourself as the delegate to receive any errors */
> mail.delegate = self;
> /* create a new outgoing message object */
> MailOutgoingMessage *emailMessage = [[[mail classForScriptingClass:@"outgoing
> message"] alloc] initWithProperties:
> [NSDictionary
> dictionaryWithObjectsAndKeys:
> [self.subjectField
> stringValue], @"subject",
> [[self.messageContent
> textStorage] string], @"content",
> nil]];
> /* add the object to the mail app  */
> [[mail outgoingMessages] addObject: emailMessage];
> /* set the sender, show the message */
> emailMessage.sender = [self.fromField stringValue];
> emailMessage.visible = YES;

Though it is not clear how this would translates over into macruby. I
have tried ever variation of MailOutgoingMessage.new and addObject.


On Tue, Oct 23, 2012 at 8:45 AM, Steve Clarke  wrote:

> Hi,
>
> I got something similar working for a plain text email but there are
> additional requirements for HTML emails (which I needed), and I couldn't
> persuade SB to accept  html content.  I should have made that clear in my
> previous note.  If anyone has an example for HTML email with SB it would be
> great to see it.
>
> Just taken a closer look at the scripting dictionary for mail and it looks
> like the "html content" property isn't documented - so who knows how I
> found it in the first place!  I just checked it out and it still works but
> obviously can't be relied on.
>
> Apologies for the red herring.  It looks as if there is no supported way
> to send html email using ScriptingBridge.
>
> Steve
>
> On 23 Oct 2012, at 15:52, Mark Rada  wrote:
>
> Hi Cliff,
>
> Did you manage to find the SBSendEmail sample code:
>
>
> https://developer.apple.com/library/mac/#samplecode/SBSendEmail/Introduction/Intro.html
>
> The sample they have looks a bit different from what you have. I haven't
> tried it out myself, but their documentation seems quite thorough and was
> updated only a year ago.
>
>
>
>
>
> On 2012-10-23, at 5:28 AM, Steve Clarke  wrote:
>
> Just had a closer look at what I did with sending mail and I think my
> earlier reply was probably  wrong, or at least not helpful.  I think the
> difficulty arises because there are some things that ScriptingBridge is
> unable to do.  I could not find a way to create an outgoing message with
> ScriptingBridge and I had to resort to running a trivial applescript (using
> NSAppleScript executeAndReturnError)  to do the job for me.  If anyone
> knows a better way I'd be delighted to hear about it!
>
> I created the applescript from a template that I modified in my code
> before I executed it.  I guess Cliff could adopt a similar approach to copy
> subject, content etc from his draft.
>
> Here's the template.  The %HTML% and %SUBJECT% are placeholders that get
> replaced by the actual values before execution.
>
> =
> tell application "Mail"
> activate
> set htmlMsg to "%HTML%"
> set subjecta to "%SUBJECT%"
> set theMsg to make new outgoing message with properties ¬
> {subject:subjecta, html content:htmlMsg & return & return, content:""}
> end tell
> =
>
> Steve
>
> On 23 Oct 2012, at 07:06, Cliff Rosson  wrote:
>
> So playing around a little with this I was able to browse and find
> messages via macruby. On the other hand I cannot figure out how to send a
> drafted email. Here is what I have so far.
>
> My drafts folder has 1 message in it ready to be sent.
>
> mail = SBApplication.applicationWithBundleIdentifier("com.apple.mail")
>> my_account = mail.accounts.select { |account| account.name ==
>> "MyAccountName" }.first
>> drafts_folder = my_account.mailboxes.select { |mailbox| mailbox.name ==
>> "Drafts" }.first
>> draft = drafts_folder.messages.first
>
>
> I need to use the send method somehow. I think I need to make a new
> MailOutgoingMessage but I would like to make this message based on my
> already existing draft message.
>
> Any know how this is done?
>
> I had hoped it would have been as simple as draft.send. :)
>
>
> On Sat, Oct 20, 2012 at 2:14 PM, Mark Rada  wrote:
>
>> Hi Rob,
>>
>> I think Colin answered this fairly well. Personally, I prefer to use GCD
>> when available because I find the API simpler and GCD stuff works with or
>> without run loops.
>>
>> --
>> Mark
>>
>>
>> On 2012-10-20, at 2:40 PM, Robert Carl Rice  wrote:
>>
>> > Hi Mark,
>> >
>> > I use NSTimer a lot in my apps. What is the advantage of using GCD API?
>> >
>> >

Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Steve Clarke
Hi Cliff,

I guess the answer may be that I didn't get it working in Macruby, as I ended 
up coding the relevant bit in Objective C!  My recollection was that I used 
Objective C so that I could write a framework that could be used from the 
system ruby rather than just macruby.  Maybe I also ended up using Objective C 
because I, like you, simply couldn't get it working in Macruby.

Unless anyone has a better idea you could maybe try using my applescript 
workround to create an outgoing message that you could then manipulate with 
ruby. Since there's no way to return directly the object that's created in 
applescript you may need to resort to saving the outgoing message within the 
script and then hopefully locating the saved message in your ruby code.  All 
very messy!  

I will however spend a few minutes trying to create a plain text message in 
Macruby.  I'll let you know if I'm successful.

Steve

On 23 Oct 2012, at 16:51, Cliff Rosson  wrote:

> Steve how did you get it working with the plain text. Below is the code I 
> think that is relevant in the SBS program.
> 
> - (IBAction)sendEmailMessage:(id)sender {
> /* create a Scripting Bridge object for talking to the Mail application */
> MailApplication *mail = [SBApplication 
> applicationWithBundleIdentifier:@"com.apple.Mail"];
> 
> /* set ourself as the delegate to receive any errors */
> mail.delegate = self;
> /* create a new outgoing message object */
> MailOutgoingMessage *emailMessage = [[[mail classForScriptingClass:@"outgoing 
> message"] alloc] initWithProperties:
> [NSDictionary 
> dictionaryWithObjectsAndKeys:
> [self.subjectField 
> stringValue], @"subject",
> [[self.messageContent 
> textStorage] string], @"content",
> nil]];
> /* add the object to the mail app  */
> [[mail outgoingMessages] addObject: emailMessage];
> /* set the sender, show the message */
> emailMessage.sender = [self.fromField stringValue];
> emailMessage.visible = YES;
> 
> 
> Though it is not clear how this would translates over into macruby. I have 
> tried ever variation of MailOutgoingMessage.new and addObject. 
> 
> 
> On Tue, Oct 23, 2012 at 8:45 AM, Steve Clarke  wrote:
> Hi,
> 
> I got something similar working for a plain text email but there are 
> additional requirements for HTML emails (which I needed), and I couldn't 
> persuade SB to accept  html content.  I should have made that clear in my 
> previous note.  If anyone has an example for HTML email with SB it would be 
> great to see it.
> 
> Just taken a closer look at the scripting dictionary for mail and it looks 
> like the "html content" property isn't documented - so who knows how I found 
> it in the first place!  I just checked it out and it still works but 
> obviously can't be relied on.  
> 
> Apologies for the red herring.  It looks as if there is no supported way to 
> send html email using ScriptingBridge.
> 
> Steve
> 
> On 23 Oct 2012, at 15:52, Mark Rada  wrote:
> 
>> Hi Cliff,
>> 
>> Did you manage to find the SBSendEmail sample code:
>> 
>> https://developer.apple.com/library/mac/#samplecode/SBSendEmail/Introduction/Intro.html
>> 
>> The sample they have looks a bit different from what you have. I haven't 
>> tried it out myself, but their documentation seems quite thorough and was 
>> updated only a year ago.
>> 
>> 
>> 
>> 
>> 
>> On 2012-10-23, at 5:28 AM, Steve Clarke  wrote:
>> 
>>> Just had a closer look at what I did with sending mail and I think my 
>>> earlier reply was probably  wrong, or at least not helpful.  I think the 
>>> difficulty arises because there are some things that ScriptingBridge is 
>>> unable to do.  I could not find a way to create an outgoing message with 
>>> ScriptingBridge and I had to resort to running a trivial applescript (using 
>>> NSAppleScript executeAndReturnError)  to do the job for me.  If anyone 
>>> knows a better way I'd be delighted to hear about it! 
>>> 
>>> I created the applescript from a template that I modified in my code before 
>>> I executed it.  I guess Cliff could adopt a similar approach to copy 
>>> subject, content etc from his draft.
>>> 
>>> Here's the template.  The %HTML% and %SUBJECT% are placeholders that get 
>>> replaced by the actual values before execution.
>>> 
>>> =
>>> tell application "Mail"
>>> activate
>>> set htmlMsg to "%HTML%"
>>> set subjecta to "%SUBJECT%"
>>> set theMsg to make new outgoing message with properties ¬
>>> {subject:subjecta, html content:htmlMsg & return & return, 
>>> content:""}
>>> end tell
>>> =
>>> 
>>> Steve
>>> 
>>> On 23 Oct 2012, at 07:06, Cliff Rosson  wrote:
>>> 
 So playing around a little with this I was able to browse and find 
 messages via macruby. On the other hand I cann

Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Steve Clarke
Hi Cliff,

I've got something simple to work in Macruby.  I think the problems I had were 
because of html content.

Here's an example for plain text:

=
framework 'Foundation'
framework 'ScriptingBridge'
TITLE="title"
def make_message
app=SBApplication.applicationWithBundleIdentifier("com.apple.Mail")
props = { 'subject'=> 'Subject 1', 'sender'=>'[email protected]', 
'content'=>'Lorem ipsum '}
msg_class = app.classForScriptingClass('outgoing message')
outgoing_msg=msg_class.alloc.initWithProperties(props)
app.outgoingMessages.addObject(outgoing_msg)
recip_class=app.classForScriptingClass('to recipient')

recipient=recip_class.alloc.initWithProperties({'address'=>'[email protected]'})
outgoing_msg.toRecipients.addObject(recipient)
outgoing_msg.send
end

make_message
=

Steve

On 23 Oct 2012, at 16:51, Cliff Rosson  wrote:

> Steve how did you get it working with the plain text. Below is the code I 
> think that is relevant in the SBS program.
> 
> - (IBAction)sendEmailMessage:(id)sender {
> /* create a Scripting Bridge object for talking to the Mail application */
> MailApplication *mail = [SBApplication 
> applicationWithBundleIdentifier:@"com.apple.Mail"];
> 
> /* set ourself as the delegate to receive any errors */
> mail.delegate = self;
> /* create a new outgoing message object */
> MailOutgoingMessage *emailMessage = [[[mail classForScriptingClass:@"outgoing 
> message"] alloc] initWithProperties:
> [NSDictionary 
> dictionaryWithObjectsAndKeys:
> [self.subjectField 
> stringValue], @"subject",
> [[self.messageContent 
> textStorage] string], @"content",
> nil]];
> /* add the object to the mail app  */
> [[mail outgoingMessages] addObject: emailMessage];
> /* set the sender, show the message */
> emailMessage.sender = [self.fromField stringValue];
> emailMessage.visible = YES;
> 
> 
> Though it is not clear how this would translates over into macruby. I have 
> tried ever variation of MailOutgoingMessage.new and addObject. 
> 
> 
> On Tue, Oct 23, 2012 at 8:45 AM, Steve Clarke  wrote:
> Hi,
> 
> I got something similar working for a plain text email but there are 
> additional requirements for HTML emails (which I needed), and I couldn't 
> persuade SB to accept  html content.  I should have made that clear in my 
> previous note.  If anyone has an example for HTML email with SB it would be 
> great to see it.
> 
> Just taken a closer look at the scripting dictionary for mail and it looks 
> like the "html content" property isn't documented - so who knows how I found 
> it in the first place!  I just checked it out and it still works but 
> obviously can't be relied on.  
> 
> Apologies for the red herring.  It looks as if there is no supported way to 
> send html email using ScriptingBridge.
> 
> Steve
> 
> On 23 Oct 2012, at 15:52, Mark Rada  wrote:
> 
>> Hi Cliff,
>> 
>> Did you manage to find the SBSendEmail sample code:
>> 
>> https://developer.apple.com/library/mac/#samplecode/SBSendEmail/Introduction/Intro.html
>> 
>> The sample they have looks a bit different from what you have. I haven't 
>> tried it out myself, but their documentation seems quite thorough and was 
>> updated only a year ago.
>> 
>> 
>> 
>> 
>> 
>> On 2012-10-23, at 5:28 AM, Steve Clarke  wrote:
>> 
>>> Just had a closer look at what I did with sending mail and I think my 
>>> earlier reply was probably  wrong, or at least not helpful.  I think the 
>>> difficulty arises because there are some things that ScriptingBridge is 
>>> unable to do.  I could not find a way to create an outgoing message with 
>>> ScriptingBridge and I had to resort to running a trivial applescript (using 
>>> NSAppleScript executeAndReturnError)  to do the job for me.  If anyone 
>>> knows a better way I'd be delighted to hear about it! 
>>> 
>>> I created the applescript from a template that I modified in my code before 
>>> I executed it.  I guess Cliff could adopt a similar approach to copy 
>>> subject, content etc from his draft.
>>> 
>>> Here's the template.  The %HTML% and %SUBJECT% are placeholders that get 
>>> replaced by the actual values before execution.
>>> 
>>> =
>>> tell application "Mail"
>>> activate
>>> set htmlMsg to "%HTML%"
>>> set subjecta to "%SUBJECT%"
>>> set theMsg to make new outgoing message with properties ¬
>>> {subject:subjecta, html content:htmlMsg & return & return, 
>>> content:""}
>>> end tell
>>> =
>>> 
>>> Steve
>>> 
>>> On 23 Oct 2012, at 07:06, Cliff Rosson  wrote:
>>> 
 So playing around a little with this I was able to browse and find 
 messages via macruby. On the other hand I cannot figure out ho

Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Cliff Rosson
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  wrote:

> Hi Cliff,
>
> I've got something simple to work in Macruby.  I think the problems I had
> were because of html content.
>
> Here's an example for plain text:
>
> =
> framework 'Foundation'
> framework 'ScriptingBridge'
> TITLE="title"
> def make_message
> app=SBApplication.applicationWithBundleIdentifier("com.apple.Mail")
> props = { 'subject'=> 'Subject 1', 'sender'=>'[email protected]',
> 'content'=>'Lorem ipsum '}
> msg_class = app.classForScriptingClass('outgoing message')
> outgoing_msg=msg_class.alloc.initWithProperties(props)
> app.outgoingMessages.addObject(outgoing_msg)
> recip_class=app.classForScriptingClass('to recipient')
> recipient=recip_class.alloc.initWithProperties({'address'=>'
> [email protected]'})
> outgoing_msg.toRecipients.addObject(recipient)
> outgoing_msg.send
> end
>
> make_message
> =
>
> Steve
>
> On 23 Oct 2012, at 16:51, Cliff Rosson  wrote:
>
> Steve how did you get it working with the plain text. Below is the code I
> think that is relevant in the SBS program.
>
> - (IBAction)sendEmailMessage:(id)sender {
>> /* create a Scripting Bridge object for talking to the Mail application */
>> MailApplication *mail = [SBApplication applicationWithBundleIdentifier:
>> @"com.apple.Mail"];
>>
>> /* set ourself as the delegate to receive any errors */
>> mail.delegate = self;
>> /* create a new outgoing message object */
>> MailOutgoingMessage *emailMessage = [[[mail classForScriptingClass:@"outgoing
>> message"] alloc] initWithProperties:
>> [NSDictionary
>> dictionaryWithObjectsAndKeys:
>> [self.subjectField
>> stringValue], @"subject",
>> [[self.messageContent
>> textStorage] string], @"content",
>> nil]];
>> /* add the object to the mail app  */
>> [[mail outgoingMessages] addObject: emailMessage];
>> /* set the sender, show the message */
>> emailMessage.sender = [self.fromField stringValue];
>> emailMessage.visible = YES;
>
>
>
> Though it is not clear how this would translates over into macruby. I have
> tried ever variation of MailOutgoingMessage.new and addObject.
>
>
> On Tue, Oct 23, 2012 at 8:45 AM, Steve Clarke wrote:
>
>> Hi,
>>
>> I got something similar working for a plain text email but there are
>> additional requirements for HTML emails (which I needed), and I couldn't
>> persuade SB to accept  html content.  I should have made that clear in my
>> previous note.  If anyone has an example for HTML email with SB it would be
>> great to see it.
>>
>> Just taken a closer look at the scripting dictionary for mail and it
>> looks like the "html content" property isn't documented - so who knows how
>> I found it in the first place!  I just checked it out and it still works
>> but obviously can't be relied on.
>>
>> Apologies for the red herring.  It looks as if there is no supported way
>> to send html email using ScriptingBridge.
>>
>> Steve
>>
>> On 23 Oct 2012, at 15:52, Mark Rada  wrote:
>>
>> Hi Cliff,
>>
>> Did you manage to find the SBSendEmail sample code:
>>
>>
>> https://developer.apple.com/library/mac/#samplecode/SBSendEmail/Introduction/Intro.html
>>
>> The sample they have looks a bit different from what you have. I haven't
>> tried it out myself, but their documentation seems quite thorough and was
>> updated only a year ago.
>>
>>
>>
>>
>>
>> On 2012-10-23, at 5:28 AM, Steve Clarke  wrote:
>>
>> Just had a closer look at what I did with sending mail and I think my
>> earlier reply was probably  wrong, or at least not helpful.  I think the
>> difficulty arises because there are some things that ScriptingBridge is
>> unable to do.  I could not find a way to create an outgoing message with
>> ScriptingBridge and I had to resort to running a trivial applescript (using
>> NSAppleScript executeAndReturnError)  to do the job for me.  If anyone
>> knows a better way I'd be delighted to hear about it!
>>
>> I created the applescript from a template that I modified in my code
>> before I executed it.  I guess Cliff could adopt a similar approach to copy
>> subject, content etc from his draft.
>>
>> Here's the template.  The %HTML% and %SUBJECT% are placeholders that get
>> replaced by the actual values before execution.
>>
>> =
>> tell application "Mail"
>>  activate
>> set htmlMsg to "%HTML%"
>> set subjecta to "%SUBJECT%"
>>  set theMsg to make new outgoing message with properties ¬
>> {subject:subjecta, html content:htmlMsg & return & return, content:""}
>> end tell
>> =
>>
>> Steve
>>
>> On 23 Oct 2012, at 07:06, Cliff Rosson  wrote:
>>
>> So playing ar

Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Steve Clarke
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  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  wrote:
> Hi Cliff,
> 
> I've got something simple to work in Macruby.  I think the problems I had 
> were because of html content.
> 
> Here's an example for plain text:
> 
> =
> framework 'Foundation'
> framework 'ScriptingBridge'
> TITLE="title"
> def make_message
>   app=SBApplication.applicationWithBundleIdentifier("com.apple.Mail")
>   props = { 'subject'=> 'Subject 1', 'sender'=>'[email protected]', 
> 'content'=>'Lorem ipsum '}
>   msg_class = app.classForScriptingClass('outgoing message')
>   outgoing_msg=msg_class.alloc.initWithProperties(props)
>   app.outgoingMessages.addObject(outgoing_msg)
>   recip_class=app.classForScriptingClass('to recipient')
>   
> recipient=recip_class.alloc.initWithProperties({'address'=>'[email protected]'})
>   outgoing_msg.toRecipients.addObject(recipient)
>   outgoing_msg.send
> end
> 
> make_message
> =
> 
> Steve
> 
> On 23 Oct 2012, at 16:51, Cliff Rosson  wrote:
> 
>> Steve how did you get it working with the plain text. Below is the code I 
>> think that is relevant in the SBS program.
>> 
>> - (IBAction)sendEmailMessage:(id)sender {
>> /* create a Scripting Bridge object for talking to the Mail application */
>> MailApplication *mail = [SBApplication 
>> applicationWithBundleIdentifier:@"com.apple.Mail"];
>> 
>> /* set ourself as the delegate to receive any errors */
>> mail.delegate = self;
>> /* create a new outgoing message object */
>> MailOutgoingMessage *emailMessage = [[[mail 
>> classForScriptingClass:@"outgoing message"] alloc] initWithProperties:
>> [NSDictionary 
>> dictionaryWithObjectsAndKeys:
>> [self.subjectField 
>> stringValue], @"subject",
>> [[self.messageContent 
>> textStorage] string], @"content",
>> nil]];
>> /* add the object to the mail app  */
>> [[mail outgoingMessages] addObject: emailMessage];
>> /* set the sender, show the message */
>> emailMessage.sender = [self.fromField stringValue];
>> emailMessage.visible = YES;
>> 
>> 
>> Though it is not clear how this would translates over into macruby. I have 
>> tried ever variation of MailOutgoingMessage.new and addObject. 
>> 
>> 
>> On Tue, Oct 23, 2012 at 8:45 AM, Steve Clarke  wrote:
>> Hi,
>> 
>> I got something similar working for a plain text email but there are 
>> additional requirements for HTML emails (which I needed), and I couldn't 
>> persuade SB to accept  html content.  I should have made that clear in my 
>> previous note.  If anyone has an example for HTML email with SB it would be 
>> great to see it.
>> 
>> Just taken a closer look at the scripting dictionary for mail and it looks 
>> like the "html content" property isn't documented - so who knows how I found 
>> it in the first place!  I just checked it out and it still works but 
>> obviously can't be relied on.  
>> 
>> Apologies for the red herring.  It looks as if there is no supported way to 
>> send html email using ScriptingBridge.
>> 
>> Steve
>> 
>> On 23 Oct 2012, at 15:52, Mark Rada  wrote:
>> 
>>> Hi Cliff,
>>> 
>>> Did you manage to find the SBSendEmail sample code:
>>> 
>>> https://developer.apple.com/library/mac/#samplecode/SBSendEmail/Introduction/Intro.html
>>> 
>>> The sample they have looks a bit different from what you have. I haven't 
>>> tried it out myself, but their documentation seems quite thorough and was 
>>> updated only a year ago.
>>> 
>>> 
>>> 
>>> 
>>> 
>>> On 2012-10-23, at 5:28 AM, Steve Clarke  wrote:
>>> 
 Just had a closer look at what I did with sending mail and I think my 
 earlier reply was probably  wrong, or at least not helpful.  I think the 
 difficulty arises because there are some things that ScriptingBridge is 
>>>

Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Cliff Rosson
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
=> 

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  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  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 wrote:
>
>> Hi Cliff,
>>
>> I've got something simple to work in Macruby.  I think the problems I had
>> were because of html content.
>>
>> Here's an example for plain text:
>>
>> =
>> framework 'Foundation'
>> framework 'ScriptingBridge'
>> TITLE="title"
>> def make_message
>> app=SBApplication.applicationWithBundleIdentifier("com.apple.Mail")
>> props = { 'subject'=> 'Subject 1', 'sender'=>'[email protected]',
>> 'content'=>'Lorem ipsum '}
>>  msg_class = app.classForScriptingClass('outgoing message')
>> outgoing_msg=msg_class.alloc.initWithProperties(props)
>>  app.outgoingMessages.addObject(outgoing_msg)
>> recip_class=app.classForScriptingClass('to recipient')
>> recipient=recip_class.alloc.initWithProperties({'address'=>'
>> [email protected]'})
>>  outgoing_msg.toRecipients.addObject(recipient)
>> outgoing_msg.send
>> end
>>
>> make_message
>> =
>>
>> Steve
>>
>> On 23 Oct 2012, at 16:51, Cliff Rosson  wrote:
>>
>> Steve how did you get it working with the plain text. Below is the code I
>> think that is relevant in the SBS program.
>>
>> - (IBAction)sendEmailMessage:(id)sender {
>>> /* create a Scripting Bridge object for talking to the Mail application
>>> */
>>> MailApplication *mail = [SBApplication applicationWithBundleIdentifier:
>>> @"com.apple.Mail"];
>>>
>>> /* set ourself as the delegate to receive any errors */
>>> mail.delegate = self;
>>> /* create a new outgoing message object */
>>> MailOutgoingMessage *emailMessage = [[[mail 
>>> classForScriptingClass:@"outgoing
>>> message"] alloc] initWithProperties:
>>> [NSDictionary
>>> dictionaryWithObjectsAndKeys:
>>>   

Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Steve Clarke
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  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
> =>  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  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  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  wrote:
>> 
>> 
>> 
>> -- 
>> http://about.me/cliffrosson
>> vizualize.me/cliffrosson
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> http://lists.macosforge.org/mailman/listinfo/macruby-devel
> 
> 
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo/macruby-devel
> 
> 
> 
> 
> -- 
> http://about.me/cliffrosson
> vizualize.me/cliffrosson
> ___
> MacRuby-devel mailing list
> [email protected]
> http://lists.macosforge.org/mailman/listinfo/macruby-devel

___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo/macruby-devel


Re: [MacRuby-devel] Basic delayed email method

2012-10-23 Thread Cliff Rosson
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@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  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  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
> =>  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 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  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 wrote:
>>
>>
>>
>> --
>> http://about.me/cliffrosson
>> vizualize.me/cliffrosson
>> ___
>> MacRuby-devel mailing list
>> [email protected]
>> http://lists.macosforge.org/mailman/