Is it possible to check for operating system?

Here is an example of how to use that to run platform-specific setup and configuration – and store a convenient global variable with the value you are looking for:

String osType;

void setup() {
  osType = osSetup();
  println(osType);
}

String osSetup () {
  String os = System.getProperty("os.name");
  if (os.contains("Windows")) {
    // os-specific setup and config here
    return "win";
  } else if (os.contains("Mac")) {
    // ...
    return "mac";
  } else if (os.contains("Linux")) {
    // ...
    return "linux";
  } else {
    // ...
    return "other";
  }
}

Note that your case detection can be anything – win32/64, or checking for a particular linux version that you know doesn’t work, or making it only “mac” vs “other”. A previous example:

3 Likes