Jump to content

Sorehead

Member
  • Posts

    8
  • Joined

  • Last visited

Posts posted by Sorehead

  1. Wow, you're fast, vitor. I appreciate your time and effort in helping me, sincerely. 

     

    I removed the two lines of code you directed me to erase. 

     

    The workflow still isn't working. I ran Alfred's Debugger and received the following...any thoughts?

     

    [19:30:16.056] Logging Started...
    [19:30:16.724] Keyboard Brightness[Hotkey] Processing complete
    [19:30:16.735] Keyboard Brightness[Hotkey] Passing output 'keyboard-brightness-up' to Run Script
    [19:30:16.866] ERROR: Keyboard Brightness[Run Script] /Users/Sorehead/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/E06D20DF-E0EE-4C54-83BB-6E0A4C5614DB:15:17: error: cannot find 'NSEvent' in scope
        let flags = NSEvent.ModifierFlags(rawValue: (down ? 0xa00 : 0xb00))
                    ^~~~~~~
    /Users/Sorehead/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/E06D20DF-E0EE-4C54-83BB-6E0A4C5614DB:17:14: error: cannot find 'NSEvent' in scope
        let ev = NSEvent.otherEvent(
                 ^~~~~~~
    /Users/Sorehead/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/E06D20DF-E0EE-4C54-83BB-6E0A4C5614DB:18:13: error: cannot find 'NSEvent' in scope
          with: NSEvent.EventType.systemDefined,
                ^~~~~~~
    /Users/Sorehead/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/E06D20DF-E0EE-4C54-83BB-6E0A4C5614DB:19:17: error: cannot find 'NSPoint' in scope
          location: NSPoint(x: 0, y: 0),
                    ^~~~~~~
    /Users/Sorehead/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/E06D20DF-E0EE-4C54-83BB-6E0A4C5614DB:23:16: error: 'nil' requires a contextual type
          context: nil,
                   ^
    /Users/Sorehead/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/E06D20DF-E0EE-4C54-83BB-6E0A4C5614DB:28:19: error: type of expression is ambiguous without more context
        let cev = ev?.cgEvent
                  ~~~~^~~~~~~
    /Users/Sorehead/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/E06D20DF-E0EE-4C54-83BB-6E0A4C5614DB:29:20: error: cannot find 'CGEventTapLocation' in scope
        cev?.post(tap: CGEventTapLocation.cgSessionEventTap)
                       ^~~~~~~~~~~~~~~~~~
    [19:30:20.181] Logging Stopped.

  2. Thanks for the quick response, vitor. I think I did what your instructions describe, but the keyboard brightness is not increasing. In fact, I don't think anything happens. 

     

    Before trying the Workflow, I set my keyboard brightness to no brightness, then tried to increase brightness using my Hotkey. I entered the Command-1 Hotkey several times. I also tried holding Command-1 down for a long time. Neither works. 

     

    Could you look at the attached pictures and the code I'm using to see what might be wrong?

     

    If important, I'm using Ventura 13.3.1 on MBP 16-in 2021. 

     

    Screenshot2023-04-19at16_58_03.png.1021d3c3f7d1bb330f051942c8a1e9ff.png

     

     

    Screenshot2023-04-19at17_00_06.thumb.png.73f02a3a2d125c475a1a91d6dc84e8dd.png

     

    And here's the code I'm running:

     

    var query = CommandLine.arguments[1]

    print(query, terminator: "")import Quartz

    let supportedKeys: [String: UInt32] = [
      "screen-brightness-up": 2,
      "screen-brightness-down": 3,
      "keyboard-brightness-up": 21,
      "keyboard-brightness-down": 22,
      "play-pause": 16,
      "fast-forward": 17,
      "rewind": 18,
      "volume-mute-toggle": 7,
      "volume-up": 0,
      "volume-down": 1,
    ]

    func pressKey(_ key: UInt32) {
      func keyDown(_ down: Bool) {
        let flags = NSEvent.ModifierFlags(rawValue: (down ? 0xa00 : 0xb00))
        let data1 = Int((key << 16) | (down ? 0xa00 : 0xb00))

        let ev = NSEvent.otherEvent(
          with: NSEvent.EventType.systemDefined,
          location: NSPoint(x: 0, y: 0),
          modifierFlags: flags,
          timestamp: 0,
          windowNumber: 0,
          context: nil,
          subtype: 8,
          data1: data1,
          data2: -1
        )

        let cev = ev?.cgEvent
        cev?.post(tap: CGEventTapLocation.cgSessionEventTap)
      }

      keyDown(true)
      keyDown(false)
    }

    pressKey(supportedKeys[CommandLine.arguments[1]]!)

×
×
  • Create New...