Re: [MacRuby-devel] Basic delayed email method

2012-10-24 Thread Cliff Rosson
So here is the lazyman's solution I came up with. #!/usr/local/bin/macruby > framework 'ScriptingBridge' > ACCOUNT = "AccountName" > DAY = Time.now.day > MONTH = Time.now.month > YEAR = Time.now.year > time_range = ((Time.now - 150)..(Time.now + 300)) > @mail = SBApplication.applicationWithBundleI

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

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

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_fold

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 abou

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

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.applicationWithBundle

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

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 applicationWithBundle

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

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 wa

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 Scriptin

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

Re: [MacRuby-devel] Basic delayed email method

2012-10-22 Thread Cliff Rosson
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.

Re: [MacRuby-devel] Basic delayed email method

2012-10-20 Thread Mark Rada
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. Wh

Re: [MacRuby-devel] Basic delayed email method

2012-10-20 Thread Cliff Rosson
> > 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/ > > AXEl

Re: [MacRuby-devel] Basic delayed email method

2012-10-20 Thread Cliff Rosson
Hi Mark, I wouldn't actually loop for an hour I was just lazily writing something as an example in chat. I'll take a look at what you provided and try to post my updates here. Thanks so much! :) -Cliff On Sat, Oct 20, 2012 at 11:50 AM, Colin Thomas-Arnold wrote: > A timer would work fine here I

Re: [MacRuby-devel] Basic delayed email method

2012-10-20 Thread Colin Thomas-Arnold
A timer would work fine here I think, but in my opinion there is a lot of value in learning GCD - but I also use NSTimers all the time, so whatever floats the boat. But the original code Cliff sent doesn't use a Timer, it assigns a time in the future and checks as often as possible that it is e

Re: [MacRuby-devel] Basic delayed email method

2012-10-20 Thread Robert Carl Rice
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 sna

Re: [MacRuby-devel] Basic delayed email method

2012-10-19 Thread Mark Rada
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