avichou Posted August 31, 2022 Posted August 31, 2022 I don't use apple music or itunes,but instead rely on youtube music (be it on chrome with youtube,or as the standalone YT music app ) Is there no way to use alfred remote to simulate the OS button press ? Such as pause,next,previous ? I would like to control my music/video from my phone using alfred remote ,isnt it possible ?
vitor Posted September 1, 2022 Posted September 1, 2022 Welcome @avichou, First, add your Remote Trigger. Connect it to a Run Script Action with language set to /usr/bin/swift and the following Script: 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]]!) Now go back to the Remote Trigger and set “Argument” to “Text”. In the text box, write one of the options at the top of the code, like fast-forward or play-pause. Duplicate the Remote Trigger and change the Text for each action you want. They can all connect to the same Run Script. The first time you run it, macOS may ask you to install the command-line developer tools. Let it (takes two clicks), and it’ll work from then on. avichou 1
avichou Posted September 2, 2022 Author Posted September 2, 2022 5 hours ago, vitor said: Welcome @avichou, First, add your Remote Trigger. Connect it to a Run Script Action with language set to /usr/bin/swift and the following Script: 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]]!) Now go back to the Remote Trigger and set “Argument” to “Text”. In the text box, write one of the options at the top of the code, like fast-forward or play-pause. Duplicate the Remote Trigger and change the Text for each action you want. They can all connect to the same Run Script. The first time you run it, macOS may ask you to install the command-line developer tools. Let it (takes two clicks), and it’ll work from then on. Thanks a lot but I really have no knowledge about that ...i really don't know what to do ahha Where is the remote trigger option so I can create a new one ?
avichou Posted September 2, 2022 Author Posted September 2, 2022 I tried another workflow but i'm thrown with this error
vitor Posted September 2, 2022 Posted September 2, 2022 (edited) Make a new Workflow and use the palette to add the objects. 11 minutes ago, avichou said: I tried another workflow but i'm thrown with this error That is unrelated and covered in another thread. Edited September 2, 2022 by vitor avichou 1
avichou Posted September 2, 2022 Author Posted September 2, 2022 (edited) So I just did what you said ,and it still doesn't work ,nothing happens Edited September 2, 2022 by avichou More details
vitor Posted September 2, 2022 Posted September 2, 2022 You have a . there, that’s not part of the name. avichou 1
avichou Posted September 2, 2022 Author Posted September 2, 2022 1 minute ago, vitor said: You have a . there, that’s not part of the name. Ahaha I just came to tell you that Thanks a lot Works wonders ! And I can use any other command,such as increase display brightness or anything ? So cool !
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now