SystemStats on OSX


#1

I need a catchall OS detection for OSX, but checking SystemStats::getOperatingSystemType() for SystemStats::OperatingSystemType::MacOSX on my OSX machine doesn’t work so I have to do (look away now!)

if(SystemStats::getOperatingSystemType() == SystemStats::OperatingSystemType::MacOSX_10_8
            || SystemStats::getOperatingSystemType() == SystemStats::OperatingSystemType::MacOSX_10_9
            || SystemStats::getOperatingSystemType() == SystemStats::OperatingSystemType::MacOSX_10_10
            || SystemStats::getOperatingSystemType() == SystemStats::OperatingSystemType::MacOSX_10_11
            || SystemStats::getOperatingSystemType() == SystemStats::OperatingSystemType::MacOSX_10_12)

#2

I have some utility functions I include in my main header which I can use throughout my app/plugin

bool isWindows()
{
#if JUCE_WINDOWS
    return true;
#else
    return false;
#endif
}

bool isSixtyFourBit()
{
#if JUCE_64BIT
    return true;
#else
    return false;
#endif
}

If you support more than Mac and Windows you can create a similar isMacOS() using JUCE_MAC

Rail


#3

That’ll do alright. Thanks. I’m still curious to know if the MacOSX OperatingSystemType is broken or not.


#4

It works fine here using SystemStats::getOperatingSystemName()

if (SystemStats::isOperatingSystem64Bit())
    Logger::writeToLog (String ("Operating System:").paddedRight (' ', iPaddingLength) + SystemStats::getOperatingSystemName() + " - [64 Bit]");
else
    Logger::writeToLog (String ("Operating System:").paddedRight (' ', iPaddingLength) + SystemStats::getOperatingSystemName());

Generates:

Operating System: Mac OSX 10.11.6 - [64 Bit]

Using:

SystemStats::OperatingSystemType type = SystemStats::getOperatingSystemType();

DBG ("Type: 0x" + String::toHexString (type).paddedLeft ('0', 4));

Generates:

Type: 0x010b

Which is correct. (MacOS 10.11.6)

To check against SystemStats::OperatingSystemType::MacOSX you have to check the correct bit.

if (SystemStats::getOperatingSystemType() & SystemStats::MacOSX)
    DBG ("Running under MacOS");

I think my free functions are a better solution for testing which platform you’re running under though.

Rail


#5

Ah thanks Rail. It makes sense now. I probably will adapt your functions for my own use. :wink: Cheers.


#6

Cool, just for clarification… my function isSixtyFourBit() reports if the current app/plugin is 64 bit – not the OS.

Cheers,

Rail


#7

But I guess I could do something like:

bool isMac()
{
#if JUCE_MACOSX
    return true;
#else
    return false;
#endif
}

#8

JUCE_MACOSX isn’t defined anywhere by JUCE… it does define JUCE_MAC

bool isMacOS()
{
    #if JUCE_MAC
        return true;
    #else
        return false;
    #endif
}

Rail


#9

True. I’m writing without docs and from my phone!


#11

I don’t see how your if statement can work but the if statement as shown in the docs doesn’t work:

if ((SystemStats::getOperatingSystemType() & SystemStats::MacOSX) != 0)

#12

I am assuming that’s a typo Fabian. Thank you, this does work. I’m going to hold my hand up now and admit to not having looked at the docs :neutral_face: