When you create Sensors for macOS devices, you must upload a script or enter the Bash, Python 3, or Zsh code in the text box provided during configuration in the Workspace ONE UEM console. The code in this script should return the values for the Sensor attributes.

Sensor Script Examples

The following examples contain the settings and the code needed.
Note: Any Sensor that returns a date-time data type value uses the ISO format.
  • Get the number of battery charge cycles:

    • Language: Bash or Zsh
    • Execution Context: System
    • Response Data Type: Integer
      /usr/sbin/ioreg -r -c "AppleSmartBattery" | grep -w "CycleCount" | awk '{print $3}' | sed -n 'p;N;'
  • Get the current Mac HostName:

    • Language: Bash or Zsh
    • Execution Context: System
    • Response Data Type: String
      /usr/sbin/scutil --get HostName
  • Get Firefox version:

    • Language: Bash
    • Execution Context: System
    • Response Data Type: String
      if [ -f "//Applications/Firefox.app/Contents/Info.plist" ] ; then
          /usr/bin/defaults read /Applications/Firefox.app/Contents/Info.plist CFBundleShortVersionString ;
      else
          echo "0" ;
  • Get current console username logged in:

    • Language: Python 3
    • Execution Context: System
    • Response Data Type: String
      from SystemConfiguration import SCDynamicStoreCopyConsoleUser
      print(SCDynamicStoreCopyConsoleUser(None, None, None)[0])