Toontje Posted March 29, 2022 Share Posted March 29, 2022 I want to send keystrokes to OBS Studio to switch scenes. Is this possible? Link to comment
vitor Posted March 29, 2022 Share Posted March 29, 2022 Seems like you’re looking for the Dispatch Key Combo Output. Do note sending keystrokes falls into GUI automation, which can be finicky. If they have a programatic way to do what you want, that would be preferable as it’s more reliable. Link to comment
Vero Posted March 30, 2022 Share Posted March 30, 2022 17 hours ago, Toontje said: I want to send keystrokes to OBS Studio to switch scenes. Is this possible? Have a look at whether it can be scripted instead, which would be a more reliable way to control it. I have a vague recollection that it can be, from looking into it a few years ago. Link to comment
Tekl Posted May 23, 2023 Share Posted May 23, 2023 I'm also looking for a way to send keys to processes like BetterTouchTool can do. Using System Events in AppleScript does need the process to be frontmost. Maybe someone knows how to use AppleScriptObjC to solve this? Maybe something using CGEventCreateKeyboardEvent. Link to comment
Tekl Posted May 23, 2023 Share Posted May 23, 2023 Well, this swift script seems to work (it sends Cmd+Up to Roon), but it only works when the Command Line Tools are installed. #!/usr/bin/env swift import Cocoa func sendShortcutToProcess(bundleIdentifier: String, keyCode: CGKeyCode, modifierFlags: CGEventFlags) { if let targetProcess = NSRunningApplication.runningApplications(withBundleIdentifier: bundleIdentifier).first { let pid = targetProcess.processIdentifier guard let eventSource = CGEventSource(stateID: .hidSystemState) else { print("Failed to create event source") return } let keyDownEvent = CGEvent(keyboardEventSource: eventSource, virtualKey: keyCode, keyDown: true)! keyDownEvent.flags = modifierFlags keyDownEvent.postToPid(pid) let keyUpEvent = CGEvent(keyboardEventSource: eventSource, virtualKey: keyCode, keyDown: false)! keyUpEvent.flags = modifierFlags keyUpEvent.postToPid(pid) } } // Usage: Call the function with the desired bundle identifier, key code, and modifier flags sendShortcutToProcess(bundleIdentifier: "com.roon.Roon", keyCode: 126, modifierFlags: .maskCommand) Link to comment
vitor Posted May 23, 2023 Share Posted May 23, 2023 2 minutes ago, Tekl said: but it only works when the Command Line Tools are installed. Unless you compile it to a binary. Having the Command Line Tools isn’t an issue, though. Link to comment
Stephen_C Posted May 23, 2023 Share Posted May 23, 2023 6 minutes ago, Tekl said: it sends Cmd+Up to Roon A simple workflow that allows volume control of Roon from Alfred without bringing the Roon app to the front would be of interest, I'm sure, to some of us. 😉 Stephen Link to comment
Tekl Posted May 23, 2023 Share Posted May 23, 2023 54 minutes ago, vitor said: Unless you compile it to a binary. Having the Command Line Tools isn’t an issue, though. Ah, good idea. But then changing scripts is more complicated and compiling Is not enough. I have to codesign and notarize it. And I don't know how to compile universal binaries. Sorry, I'm no developer, I don't want it complicated. 😁 It seems that a corresponding makefile will be bigger than the simple swift script. Link to comment
Tekl Posted May 23, 2023 Share Posted May 23, 2023 1 hour ago, Stephen_C said: A simple workflow that allows volume control of Roon from Alfred without bringing the Roon app to the front would be of interest, I'm sure, to some of us. 😉 Stephen Here's my first version: https://tekl.de/downloads/alfred-workflows/Volume Control for Roon.alfredworkflow Link to comment
Stephen_C Posted May 23, 2023 Share Posted May 23, 2023 Many thanks for that. I'll probably not now have the chance to try it until tomorrow morning (UK time) but will definitely have a look at it. It was something I was thinking about only the other day but I'm much less of a programmer than you clearly are! Stephen Link to comment
RickB Posted August 15, 2023 Share Posted August 15, 2023 I just downloaded this and it doesn't seem to be working. It is registering that Roon is running, (it shows the volume up/down icon on the screen as the script indicates) but the volume doesn't change. Any ideas? Link to comment
Stephen_C Posted August 15, 2023 Share Posted August 15, 2023 Welcome the forum. I use that workflow daily and it works perfectly for me so we have to try to discover why it's not working for you. To do that: make sure Roon is running; turn on the debugger; run the workflow and try to change the Roon volume. Copy and paste the dbugger output into a new post in this thread so that we can take a look at it. It might be helpful at the same time to confirm your macOS, Alfred and Roon version numbers. Stephen Link to comment
RickB Posted August 15, 2023 Share Posted August 15, 2023 From the debugger I saw an xcrun error. I reinstalled the Command Line tools and that fixed it!! That was my first experience working with the Alfred debugger. Thanks for responding!! Rick Link to comment
Stephen_C Posted August 16, 2023 Share Posted August 16, 2023 I'm glad it's sorted: it's a really useful little workflow. Stephen Link to comment
RickB Posted August 17, 2023 Share Posted August 17, 2023 So I tried editing the workflow to add a Play/Pause Roon. My thinking was that keycode 49 would send the spacebar to Roon. I copied the workflow block, changed the keycode sent to 49 and updated the on-screen message. When I run it, I get the on-screen message so it's triggering, but nothing happens with Roon. Any ideas? Link to comment
Stephen_C Posted August 17, 2023 Share Posted August 17, 2023 1 hour ago, RickB said: So I tried editing the workflow to add a Play/Pause Roon. I'm afraid I'm not familiar with Swift. I simply use the pause function key on my MacBook Pro keyboard which works when Roon is playing. Stephen Link to comment
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