Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcuts CLI Run Command Issue/Bug? #3

Open
SENTINELITE opened this issue Jan 13, 2022 · 0 comments
Open

Shortcuts CLI Run Command Issue/Bug? #3

SENTINELITE opened this issue Jan 13, 2022 · 0 comments

Comments

@SENTINELITE
Copy link
Owner

This one's been in the codebase, practically since its inception. I've tried digging into it, but I can't seem to find out why the execution fails.

What ends up happening: The code will execute up past the .launch() command. The execution gets "buffered", until we terminate/close the StreamDeck Software. Then they will all immediately get executed.

The below CLI commands execute perfectly, it's only when we try to run a shortcut, that it "hangs". The fact that these execute tells me that this is a deep underlying problem…
shortcuts list shortcuts list folders shortcuts list YourFolderName

I tried embedding another CLI-Helper tool, that just took the shortcut name & ran the actual shortcut via the CLI command, but that still had the same side effect.

I've tested & it appears that the only other work-arounds are saving to a text file & passively reading that, or implementing a WebSocket connection. This would require the helper app to be implemented, though.

The function below is where most of this happens. In the current codebase I've commented out the function until we find a fix.

If you'd like to test this out for yourself, or know how to fix this, you'll need to do the following:

  1. Uncomment the launchCommand() function.
  2. Under the keyDown() function inside the CounterPlugin class, in the streamdeck-backend.swift file, you'll need to replace that code with the appropriate `launchcommand().
  3. Build & extract the StreamDeck-Shortcuts executable under your Products' folder in your Derived Data. Otherwise, you can build it as a Product & export the built product.
  4. With the executable in hand, head on over to: ~Library/Application Support/com.elgato.StreamDeck/Plugins/com.sentinelite.streamdeckshortcuts.sdPlugin & replace the StreamDeck-Shortcuts file with the new one.
  5. Lastly, open up the Console.app & search for StreamDeck-Shortcuts, start monitoring, & restart the SD Software!

If anyone has any pointers, or can attempt to fix this, I'm all ears!

`swift
func launchCommand (inputShortcut: String) {
let shortcutCLI = Process()
shortcutCLI.executableURL = URL(fileURLWithPath: "/usr/bin/shortcuts")
shortcutCLI.arguments = ["run", "(inputShortcut)"]
var pipe = Pipe()

    shortcutCLI.standardOutput = pipe
    NSLog("🔳 PT3.5!")
    do{
        NSLog("🔳 PT4.5!")
        try shortcutCLI.launch() //Run doesn't work either. | .launch is deprecated.
        NSLog("🚨 Execution hangs here until parent process ends...")
        //None of the code below runs after the fact either, which makes sense.
        let data = pipe.fileHandleForReading.readDataToEndOfFile()
        NSLog("🔳 PT6.5!")
        if let output = String(data: data, encoding: String.Encoding.utf8) {
            NSLog("🔳 PT7.5!")
            NSLog(output)
            print("FinisheD Running!")
        }
    } catch {
        //    It refuses to throw an error, becuase it's waiting to execute, when the app closes?
        NSLog("Failed to run with Error \(error)")
    }
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant