I'm getting some weird behavior when trying to execute another command-line tool from my exec app. It works fine, but for some reason when using the shortcuts run YourShortcut
, we only get to the specified line, where the command “hangs”, until the parent process exits.
Now the really strange part: When using other CLI commands it executes as we’d expect. Using other Shortcuts commands shortcuts list
works, & we get the data. It’s only when we try to shortcuts run YourShortcut
that the CLI command fails.
I’ve been stumped on this for a good month to two. My workaround was to use AppleScript, but it’s really not efficient. It’s very verbose & way over-complicated to what should just work. Ideally, I want to gut out the AppleScript core & replace it with the Shortcuts CLI.
To give a brief overview of the app's architecture, which is a plugin for another 3rd party app:
- StreamDeck.app
- Our custom .exec
- Spawned CLI process
- (optional) Sister process, which communicate via it's own CLI tool or websockets.
- Our custom .exec
I’ll also add, that spawning a sister process/app that I was passing the shortcutName to, had the same effect. For the life of me, I can’t seem to solve this. The only other thing that seems like it would work is running a web-socket connection to the side app. I’ve done some preliminary testing & that appears to work, but again, this seems overkill for such a simple problem...
func launchCommand (inputShortcut: String) {
let shortcutCLI = Process()
shortcutCLI.executableURL = URL(fileURLWithPath: "/usr/bin/shortcuts")
shortcutCLI.arguments = ["run", command]
do{
try shortcutCLI.launch()
//None of the code below runs after the fact either, which makes sense.
//Capture Pipe output & print logic...
} catch {
//It refuses to throw an error, because it's waiting to execute, when the app closes?
NSLog("Failed to run with Error \(error)")
}
}
I've tried variations of the command, without fail, it won't actually launch the Shortcut until the parent process exits/terminates
I got some pointers & tried some things based off stackotter's feedback, which you can see below, but we were unable to resolve it.
func launchCommand (inputShortcut: String) {
let shortcutCLI = Process()
shortcutCLI.executableURL = URL(fileURLWithPath: "/usr/bin/nohup")
shortcutCLI.arguments = ["/bin/bash", "-c", "/usr/bin/shortcuts run \(inputShortcut) >/dev/null 2>&1 &"]
//The rest of the function
}
If you want to test/run it, I've attached the repo. Please note: You will need a StreamDeck device, either physical or the mobile app, which has a free 1-month trial. You'll also need to be running macOS 12.0+.
I'd appreciate any feedback/suggestions on how to best proceed.
Thanks,
SENTINELITE