# Is it possible to check for operating system?

**URL:** <https://discourse.processing.org/t/is-it-possible-to-check-for-operating-system/14180>\
**Category:** Processing for Android\
**Created:** [September 24, 2019, 7:52pm UTC](https://discourse.processing.org/t/is-it-possible-to-check-for-operating-system/14180 "2019-09-24T19:52:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oskarino](https://avatars.discourse-cdn.com/v4/letter/o/3ec8ea/32.png) [@oskarino](https://discourse.processing.org/u/oskarino)\
**Post date:** [September 24, 2019, 7:52pm UTC](https://discourse.processing.org/t/is-it-possible-to-check-for-operating-system/14180/1 "2019-09-24T19:52:57Z")

</div>

I have written a piece of code for Windows, and would like to use almost entirely the same piece of code for Android, just with a few minor changes (in particular screen size and mouse activity). Instead of copying the code over to APDE and making the changes there, is it possible to check which operating system is running and apply the appropriate logic so that I can use the same code for each? Thanks

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [September 24, 2019, 10:45pm UTC](https://discourse.processing.org/t/is-it-possible-to-check-for-operating-system/14180/2 "2019-09-24T22:45:29Z")

</div>

```auto
  println( "System : " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch") );

```

try on different systems and look for a string to compare

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 25, 2019, 3:59pm UTC](https://discourse.processing.org/t/is-it-possible-to-check-for-operating-system/14180/3 "2019-09-25T15:59:23Z")

</div>

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:

```auto
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:

- [Physically based rendering library for Processing SimplePBR](https://discourse.processing.org/t/physically-based-rendering-library-for-processing-simplepbr/8152/6)

---

<div class="post-metadata">

**Author:** ![oskarino](https://avatars.discourse-cdn.com/v4/letter/o/3ec8ea/32.png) [@oskarino](https://discourse.processing.org/u/oskarino)\
**Post date:** [September 25, 2019, 4:13pm UTC](https://discourse.processing.org/t/is-it-possible-to-check-for-operating-system/14180/4 "2019-09-25T16:13:45Z")

</div>

Thanks @kll !  
👍 👍 👍

---

<div class="post-metadata">

**Author:** ![oskarino](https://avatars.discourse-cdn.com/v4/letter/o/3ec8ea/32.png) [@oskarino](https://discourse.processing.org/u/oskarino)\
**Post date:** [September 27, 2019, 11:25am UTC](https://discourse.processing.org/t/is-it-possible-to-check-for-operating-system/14180/5 "2019-09-27T11:25:38Z")

</div>

That’s fantastic @jeremydouglass, thanks for the help 😄

---

<div class="post-metadata">

**Author:** ![clankill3r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/clankill3r/32/1098_2.png) [@clankill3r](https://discourse.processing.org/u/clankill3r)\
**Post date:** [June 21, 2021, 4:33pm UTC](https://discourse.processing.org/t/is-it-possible-to-check-for-operating-system/14180/6 "2021-06-21T16:33:18Z")

</div>

there is already:

`platform`

which can be checked against `MACOS` `WINDOWS` `LINUX` and `OTHER`. I think it would make sense at this point that `ANDROID` would be added as well.
