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!
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
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
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
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 ^^
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();
}
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.