I'm working with a teensy in the Arduino IDE as a USB keyboard and can get it to open browser (Chrome or Firefox) and go to a random specified web page upon a button push (or other digital input). Think of it like a physical version of StumbleUpon. Now I am wondering if it is possible to to add an if/else conditional to the code to check first to see if the browser is already open so it doesn't go through the process of reopening the browser. Is it possible to determine if a process (the browser) is already running in OS X? How would I do this? Similarly, if it is open is there a way to call the program to the forefront?
Currently I have something that takes advantage of Spotlight that is a complete kludge, but works! I know there's got to be a more elegant solution. It just sends keyboard commands (apple-space, "Firefox", enter...).
Here's the void loop:
void loop(){
if(digitalRead(0)==LOW)
{
Keyboard.set_modifier(MODIFIERKEY_GUI);
Keyboard.send_now();
Keyboard.set_key1(KEY_SPACE);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
delay(500);
Keyboard.print("Firefox");
Keyboard.set_key1(KEY_ENTER);
Keyboard.send_now();
Keyboard.set_key1(0);
delay(1000);
Keyboard.set_modifier(MODIFIERKEY_GUI);
Keyboard.send_now();
Keyboard.set_key1(KEY_L);
Keyboard.send_now();
Keyboard.set_modifier(0);
Keyboard.set_key1(0);
Keyboard.send_now();
Keyboard.print(names[random(0,NUMBER_OF_PAGES)]);
Keyboard.set_key1(KEY_ENTER);
Keyboard.send_now();
Keyboard.set_key1(0);
delay(1000);
}
}
Thanks!