I’m hoping to be able to detect which operating system a Grasshopper definition is running on.
I’ve tried using GHpython and code such as:
But no success yet.
Has anyone else been able to detect the OS from inside Grasshopper?
My use case is to be able to concatenate file paths with folder structures separated by \ for Windows or / for MacOS.
I am not a Python guy but does this help ?
I use Windows
You can also use this native Python module:
Ah thanks very much to both of you!
I’ve just switched a definition from Windows to MacOS and my importing file paths are broken.
It would be perfect if your first suggestion, Laurent, worked on MacOS like it does in Windows but unfortunately I get an error:
'System.IO' object has no attribute 'DirectorySeparatorChar'
But the platform.system() function suggested by both of you works!
Also Anders thanks for patiently re-answering this question. I did genuine searches for answers and didn’t come across your previous post answering this question.
As a follow up question to the community:
Does anyone know why
exists on Windows but not on MacOS?
You might want to have a look at the native
os.path Python module. It has the
os.path.join() function, designed for constructing platform agnostic paths.
No worries. Regarding the separator concern, as I recall you can get that using
Edit: I didn’t fully recall, it’s just
Ah thanks for this too. I will test on my Mac when I get home later.
Yup I’m using
os.sep and it works.
Regarding your original question, you can get the OS specific information with the
On macOS, it will output
Darwin as system, because that’s the underlying Unix base system. I mean, why not point out the best part of a product?