0

I want to use MacRuby to tell Mail.app to check for new email. But I cannot figure out how to go about this after I get an application reference using SBApplication.

I have the following simple script:

#!/usr/local/bin/macruby
framework 'ScriptingBridge'

mail = SBApplication.applicationWithBundleIdentifier("com.apple.mail")
# mail.check_for_new_mail?

Basically I want to do the following AppleScript in MacRuby:

tell application "Mail"
    check for new mail
end tell

Yes, I can just use the AppleScript. But I much prefer Ruby.

Diego Barros
  • 2,071
  • 2
  • 33
  • 45

1 Answers1

3

#!/usr/local/bin/macruby
framework 'ScriptingBridge'

mail = SBApplication.applicationWithBundleIdentifier("com.apple.mail")
mail.accounts.each {|account| mail.checkForNewMailFor(account) }

tip: use puts (mail.methods(true,true) - Object.new.methods) which returns available cocoa only methods list for object and ancestors

Sean Mateus
  • 161
  • 1
  • 9