Detect which OS the Arduino is connected to

Hi, is there any way to detect which operating system the Arduino (Leonardo, in my case) is connected to?

Thanks in advance

No. the Arduino is just a dumb serial device at that point. It has no way of knowing or controlling anything on the PC by itself.

I think there would need to be an application on the computer running that would send that information to the Arduino (over Serial would be the obvious way).

Probably not really what you're looking for, but you can get some information on which OS the current program was uploaded from via the FILE macro. If the path separators are backslashes you know it's Windows. If forward slash it's Linux, etc. or macOS/OS X. I don't know if there are ways to parse that string for more information.

Seems like an XY problem... why would you care ?

Thanks pert, I will try with the FILE pre-defined macro.

Answering to J-M-L, I'm trying to write a program that, depending on the OS, opens a text application and writes some text on it, for example TextEdit in macOS or Notepad in Windows. That is why I want to detect which OS, so that I can know what app to open and how to open it. I already have a function for opening a text app in macOS and doing what I want, I can write a function for Windows but then I would need to know when to call which function.

I don't know of any OS that automatically responds to commands from a newly connected serial port. No matter what OS, you would have to execute specific programs to do that.

aarg:
I don't know of any OS that automatically responds to commands from a newly connected serial port.

True, but a newly connected USB keyboard...
I suspect the OP wants something like the USB Rubber Ducky (USB Rubber Ducky - Hak5) but doesn't want to pay $44.99.

johnwasser:
True, but a newly connected USB keyboard...

Yes, possible with the Leonardo. But then how would the PC know where to send information to reach the Leo?

aarg:
Yes, possible with the Leonardo. But then how would the PC know where to send information to reach the Leo?

If I gave you a keyboard and told you to set up a computer to talk to a Leonardo you could do it. If you knew a couple of things about the particular computer you might could even do it blind and headless. Why couldn't the Leonardo do the same itself?

Delta_G:
If I gave you a keyboard and told you to set up a computer to talk to a Leonardo you could do it.

But I think I would actually need my eyes. :slight_smile:

johnwasser:
I suspect the OP wants something like the USB Rubber Ducky (USB Rubber Ducky - Hak5) but doesn't want to pay $44.99.

Apparently that device can't detect the OS either.

No, what makes you think that it should be able to? That's kind of the point of the universal serial bus is that it doesn't make any distinction about what sort of thing is driving it at either end.

That would be a massive security risk if plugging in any usb device using a standard driver could trigger the launch of a random application without configuration

That's the whole point of rubber ducky et al. Plugging in a USB device can trigger the launch of an application because that USB device can emulate a HID keyboard or mouse and do anything the user could do with a keyboard and mouse.