Skip to content

Razer support broken on Sonoma - hidutil now requires sudo #3337

Description

@latenitefilms

Reported by Ross Batten via phone call.

Currently CommandPost uses hidutil to disable the default keyboard layout for Razer devices.

Essentially we remap the Razer device so that all the built-in buttons don't actually "type" anything. Then in our Objective-C Extension (hs.razer) we detect the button presses there.

This has always worked fine in the past, but interestingly Ross is having issues on his machine.

He has a Mac Studio running Ventura - and it's all working fine there. However, he cloned his operating system to an external SSD, and when booting from the external SSD, things no longer work. Given that it's exactly the same hardware, same operating system, and same configuration, makes me think it's some kind of security issue. However, I tried disabling and re-enabling all the various permissions CommandPost needs and it didn't seem to make a difference.

Interestingly however, when looking into this, it seems that hidutil stopped working on macOS Sonoma 14.2, which was fixed in macOS Sonoma 14.3 - but now requires sudo (see here).

I'm currently running macOS 14.3, and it looks like it's broken on my machine.

For a Razer Orbweaver Chroma for example, we use the following Terminal command:

hidutil property --matching '{"ProductID":0x0207}' --set '{"UserKeyMapping":[
   {"HIDKeyboardModifierMappingSrc":0x700000051,
     "HIDKeyboardModifierMappingDst":0x100000023
   },
   {"HIDKeyboardModifierMappingSrc":0x700000039,
     "HIDKeyboardModifierMappingDst":0x100000011
   },
   {"HIDKeyboardModifierMappingSrc":0x70000002B,
     "HIDKeyboardModifierMappingDst":0x100000006
   },
   {"HIDKeyboardModifierMappingSrc":0x700000006,
     "HIDKeyboardModifierMappingDst":0x100000019
   },
   {"HIDKeyboardModifierMappingSrc":0x70000001A,
     "HIDKeyboardModifierMappingDst":0x100000008
   },
   {"HIDKeyboardModifierMappingSrc":0x70000004F,
     "HIDKeyboardModifierMappingDst":0x100000025
   },
   {"HIDKeyboardModifierMappingSrc":0x70000001B,
     "HIDKeyboardModifierMappingDst":0x100000018
   },
   {"HIDKeyboardModifierMappingSrc":0x700000052,
     "HIDKeyboardModifierMappingDst":0x100000022
   },
   {"HIDKeyboardModifierMappingSrc":0x700000050,
     "HIDKeyboardModifierMappingDst":0x100000024
   },
   {"HIDKeyboardModifierMappingSrc":0x700000021,
     "HIDKeyboardModifierMappingDst":0x100000004
   },
   {"HIDKeyboardModifierMappingSrc":0x700000035,
     "HIDKeyboardModifierMappingDst":0x100000021
   },
   {"HIDKeyboardModifierMappingSrc":0x70000002C,
     "HIDKeyboardModifierMappingDst":0x100000020
   },
   {"HIDKeyboardModifierMappingSrc":0x700000004,
     "HIDKeyboardModifierMappingDst":0x100000012
   },
   {"HIDKeyboardModifierMappingSrc":0x700000015,
     "HIDKeyboardModifierMappingDst":0x100000010
   },
   {"HIDKeyboardModifierMappingSrc":0x700000020,
     "HIDKeyboardModifierMappingDst":0x100000003
   },
   {"HIDKeyboardModifierMappingSrc":0x70000001E,
     "HIDKeyboardModifierMappingDst":0x100000001
   },
   {"HIDKeyboardModifierMappingSrc":0x70000001D,
     "HIDKeyboardModifierMappingDst":0x100000017
   },
   {"HIDKeyboardModifierMappingSrc":0x700000019,
     "HIDKeyboardModifierMappingDst":0x100000026
   },
   {"HIDKeyboardModifierMappingSrc":0x700000008,
     "HIDKeyboardModifierMappingDst":0x100000009
   },
   {"HIDKeyboardModifierMappingSrc":0x700000016,
     "HIDKeyboardModifierMappingDst":0x100000013
   },
   {"HIDKeyboardModifierMappingSrc":0x700000014,
     "HIDKeyboardModifierMappingDst":0x100000007
   },
   {"HIDKeyboardModifierMappingSrc":0x7000000E1,
     "HIDKeyboardModifierMappingDst":0x100000016
   },
   {"HIDKeyboardModifierMappingSrc":0x700000009,
     "HIDKeyboardModifierMappingDst":0x100000015
   },
   {"HIDKeyboardModifierMappingSrc":0x700000007,
     "HIDKeyboardModifierMappingDst":0x100000014
   },
   {"HIDKeyboardModifierMappingSrc":0x70000001F,
     "HIDKeyboardModifierMappingDst":0x100000002
   },
   {"HIDKeyboardModifierMappingSrc":0x700000022,
     "HIDKeyboardModifierMappingDst":0x100000005
   }, ]
}'

If I try this on macOS 14.3 I get the error:

Run as root to remap alphanumerics / special characters with UserKeyMapping

If I run with sudo, it works.

However, Ross is currently running macOS Ventura - so I think this might not be his specific issue.

I'm not really sure what the solution is here, as we don't really want CommandPost to have root access.

For reference, here's the Lua code that triggers hidutil:

--- hs.razer:defaultKeyboardLayout(enabled) -> boolean
--- Method
--- Allows you to remap the default Keyboard Layout on a Razer device so that the buttons no longer trigger their factory default actions, or restore the default keyboard layout.
---
--- Parameters:
---  * enabled - If `true` the Razer default will use its default keyboard layout.
---
--- Returns:
---  * The `hs.razer` object.
---  * `true` if successful otherwise `false`
function razerObject:defaultKeyboardLayout(enabled)
  local productID = "0x" .. string.upper(string.format("%04x", self:_productID()))
  local remapping = self:_remapping()

  if not remapping then
    log.ef("This Razer device does not support remapping.")
    return false
  end

  local command = [[hidutil property --matching '{"ProductID":]] .. productID .. [[}' --set '{"UserKeyMapping":[]] .. "\n"
  for realID, dummyID in pairs(remapping) do
    local src = enabled and realID or dummyID
    local dst = enabled and dummyID or realID
    command = command .. [[   {"HIDKeyboardModifierMappingSrc":]] .. src .. [[,]] .. "\n"
    command = command .. [[     "HIDKeyboardModifierMappingDst":]] .. dst .. "\n"
    command = command .. [[   },]] .. "\n"
  end
  command = command:sub(1, #command - 1)
  command = command .. " ]" .. "\n"
  command = command .. "}'"

  local _, status = execute(command)
  return self, status == true
end

Activity

  1. added this to the 1.4.27 milestone on May 2, 2024
  2. self-assigned this
    on May 2, 2024
  3. modified the milestones: 1.4.27, 1.4.28 on Jun 21, 2024
  4. latenitefilms commented on Aug 11, 2024

    @latenitefilms
    ContributorAuthor

    As a workaround - you can use this code:

    status = cp.tools.executeWithAdministratorPrivileges(command:gsub('"', '\\"'))

    Here:

    image

  5. latenitefilms commented on Aug 28, 2024

    @latenitefilms
    ContributorAuthor

    There is a way to grant password-less sudo access to /usr/bin/hidutil - but it's a pretty scary setup process:

    • Basically you need to run sudo visudo from macOS Terminal - this opens up a special file in a command line text editor - normally VIM.
    • And add this near the bottom: USERNAME ALL = (ALL) NOPASSWD: /usr/bin/hidutil (where USERNAME is your user name, and there's a tab between USERNAME and ALL). Do this by pressing i to go into edit mode, scroll down with your arrow keys, and add this entry after the %admin entry, press ESC, then type :x to save and exit.
    • You can then run sudo cat /etc/sudoers to see if it actually changed.

    This is helpful for navigating VIM: https://phoenixnap.com/kb/how-to-vim-save-quit-exit

    For example, it looks like this on my machine:

    image

    You will also need to modify the Lua file inside CommandPost to add sudo:

    image

  6. latenitefilms commented on Oct 8, 2024

    @latenitefilms
    ContributorAuthor

    This seems to be fixed in macOS 15!

  7. modified the milestones: 1.4.28, 1.4.29 on Oct 8, 2024
  8. modified the milestones: 1.5.2, 1.5.3 on Dec 6, 2024
  9. modified the milestones: 1.5.3, 1.5.4 on Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions