I want to press a button and open an application on my Mac. So far I figured out I need to print out a serial and then use Python to open the application. The serial printing works and also on my mac terminal, put I do not know how to receive it in python and then use that to open the application.
This is my code in Arduino
void setup() {
// put your setup code here, to run once:
pinMode(5, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(5) == LOW) {
Serial.println("hello");
}
delay(100);
}
And this is my code in python
import serial
ser = serial.Serial(port='/dev/tty.usbmodem11301',baudrate=9600)
while True:
value= ser.readline()
valueInString=str(value, 'UTF-8')
print(valueInString)
I just followed a tutorial on youtube for the python code, but it is not working. What am I doing wrong and how will I fix my problem?
I have a Mac. I need a lot more information to guide you. You say 'press a button to open an app' then talk about Arduino Serial and Python. Sorry, those are two different things.
Sorry, what I meant was I want it so when I press the button an application opens on my mac. But I found out to do that you need to have it so when you press the button you print out a serial and then you get that serial to python and then let python open the application since you cannot do it directly from arduino.
It may be technically possible, but WHY?.
Tell us what you want to do, don't give us what you think the solution is. That means no mention of Serial or Python.
What has this to do with Arduino?
Where is the button?
I'm not familar with MACs but I'm reasonably sure that you can use an Arduino that can act as a keyboard (e.g. Arduino Micro or SparkFun Pro Micro).
The same keystrokes that you use to start an application using a keyboard can be send by the above Arduinos.
E.g. in Windows you can use \CTRL><ESC> to open the start menu, next type run and in the dialog box that pops up type the name of the application and press <enter>. You can send those same keystrokes from the Arduino.
Have you got Apple Script on your Mac? I have used it to do exactly this sort of problem. No Python is needed. Although it might not be available on some more modern Macs.
Having an arduino posing as a keyboard and sending the shortcut to open spotlight (commandspace bar if you did not tailor it) then entering the app name and validating would probably work.
Otherwise look at Automator it’s available in macOS.