Go Down

Topic: OS X: arduino + adium and gmail (Read 1 time) previous topic - next topic

Mexduino

Feb 21, 2009, 02:09 am Last Edit: Feb 21, 2009, 03:34 am by formatc1702 Reason: 1
hello!

basically what i want to do right now is have a led on the arduino flash when i either have unread mail in my gmail inbox, or when i have unread messages in adium.

my question: what is the best approach here?

i have been able to retrieve the number of unread messages in gmail using IMAP and the javax.mail library.

can i access adium through processing? using applescript, perhaps? it seems to be fairly easy to use, but i have no experience at all.

maybe someone has already done this, or something similar, and is able to share his/her code here? i would appreciate it!
thanks!

[size=20][ch12377][ch12372][ch12356][ch65281][/size]

melka

http://processing.org/hacks/hacks:applescript

http://trac.adiumx.com/wiki/AppleScript_Support_1.2
http://melka.one.free.fr/blog/
http://www.flickr.com/photos/melkaone/

Mexduino

#2
Feb 21, 2009, 01:19 pm Last Edit: Feb 21, 2009, 01:21 pm by formatc1702 Reason: 1
hi!

thank you for the links, but i cannot seem to find a function in either of them that fits my needs.

method A:
if i use the myScript.execute command (first link), i see no way in the adium applescript page to determine whether i have unread messages. is there some sort of dictionary with ALL applescript functions adium supports?

or else: method B
if i configure adium to launch a certain applescript every time  a message is recieved (using the adium preferencs window) - how can i make my processing code react to that script? (the processing code needs to be already running because it also handles other events)
i would need some kind of event handler, or whatever it's called in processing.

method C:
...or the applescript could change some data which the processing code checks every 5 seconds or so and reacts to a change. but this is more of an indirect method and i would prefer A or B.

i hope you get what i mean, see the attached picture for a graphical representation  :D

any advice on this front?



thanks for advice!

[size=20][ch12377][ch12372][ch12356][ch65281][/size]

melka

O Hai

Thinking fast, I guess the easiest way is the third.

First would be the best (that's what I thought about). I did not take time to browse the adium applescript doc, but I'll have a look at it later.

I'm not sure the second would be possible. I don't know if you can poll Java apps.

Gotta go, but I'll check it when I come back.

NB : you should post that lovely sketch to the "User Experience Sketches" group on flickr, they'll love that ^^
http://flickr.com/groups/uxsketches/pool/
http://melka.one.free.fr/blog/
http://www.flickr.com/photos/melkaone/

Mexduino

hey!

okay after some random clicking, i found the "open dictionary" menu item in the script editor. and turns out, there is an unread message count property.
i managed to write a script that displays the total number of unread messages.
now the question is: how do i call that script from processing?
do i do one myScript.execute() per line? or do i cram it all in one line? and where does the result (x) go?

here's the script, i just need to cram it into processing now  :D

Code: [Select]
tell application "Adium"
     set x to 0
     repeat with theChat in (every chat)
           set x to x + (unread message count of theChat)
     end repeat
     say "You have " & x & " unread messages"
end tell


i'll look into that flickr group as well, thanks hehehe

[size=20][ch12377][ch12372][ch12356][ch65281][/size]

melka

Here's a processing sketch that polls adium using the applescript you gave earlier.
It returns an integer.
Nobody never talks to me, so I always get 0, but it should work ^^

Code: [Select]

import com.apple.cocoa.foundation.*;

void setup() {
 size(400,400);
 int adiumUnread = runAS();
 println(adiumUnread);
}

void draw() {
 
}

public int runAS() {
 String script = "tell application \"Adium\"\n"
 +"  set x to 0\n"
 +"    repeat with theChat in (every chat)\n"
 +"    set x to x + (unread message count of theChat)\n"
 +"    end repeat\n"
 +"  end tell\n"
 +"  x";
 NSAppleScript myScript = new NSAppleScript(script);
 NSMutableDictionary errors = new NSMutableDictionary();
 NSAppleEventDescriptor result = myScript.execute(errors);
 return result.int32Value();
}
http://melka.one.free.fr/blog/
http://www.flickr.com/photos/melkaone/

Mexduino

#6
Feb 21, 2009, 08:29 pm Last Edit: Feb 21, 2009, 08:34 pm by formatc1702 Reason: 1
hi!

thanks for that. however, it says it can't find the package com.apple.cocoa

where can i find it, and how can i make processing see it? i am already using javax.mail and i just had to copy it to the /code folder inside my sketch folder.

[size=20][ch12377][ch12372][ch12356][ch65281][/size]

melka

Sorry, I forgot about that.
The package is already present on macosx systems, but a bit find to hard.
Here's the way to have it working

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=LibraryProblems;action=display;num=1225564736
http://melka.one.free.fr/blog/
http://www.flickr.com/photos/melkaone/

Mexduino

wonderful! it works perfectly! e-mail and adium notifications on the arduino!

thanks a lot for all the help... i'm slowly getting into processing after all! (and a bit of applescript on the way)

[size=20][ch12377][ch12372][ch12356][ch65281][/size]

melka

http://melka.one.free.fr/blog/
http://www.flickr.com/photos/melkaone/

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy