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 Share Posted May 23 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 Share Posted May 23 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 Share Posted May 23 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 Share Posted May 23 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 Share Posted May 23 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 Share Posted May 23 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 Share Posted May 23 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
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