This bug/issue has been bugging me for many months. I've sunk hours trying to solve it. Any help/direction is super welcome!
When trying to run the following function it always throws an error when using certain diacritics (ä, etc.)
My end goal: Allow any language's special characters to be passed into the CLI interface.
func runShortcut(inputShortcut: String) {
let shortcutsCLI = Process()
shortcutsCLI.standardInput = nil //TODO: DTS Fix. This allows us to run the Shortcut!!!
shortcutsCLI.executableURL = URL(fileURLWithPath: "/usr/bin/shortcuts")
shortcutsCLI.arguments = ["run", inputShortcut.decomposedStringWithCanonicalMapping] //decomposedStringWithCanonicalMapping / composed
print("Full args: ", shortcutsCLI.arguments) //Prints: Optional(["run", "ä"])
do {
try shortcutsCLI.run()
print("Should've ran the shortcut...")
} catch {
print("\(error)")
}
}
runShortcut(inputShortcut: "ä")
I've tried forming the input "string" as Unicode let str = "\u{00c4}", formed from binary, etc. Doesn't seem to matter how I get to the character/string "ä", it refuses to work.
I've also tried str.precomposedStringWithCanonicalMapping & str.precomposedStringWithCanonicalMapping, both unsuccessful.
Everything works fine, running from the CLI, Python & Go. I strongly believe it has something to do with how the string is being passed into the Process().
With that being said, I'm unsure if it's an issue with the String that's being passed in, or if it's an underlying issue with the Process().
I have saved the inputShortcut variable to a local .txt file, then using this command cat "/PathToTxt/a.txt" | xargs shortcuts run, & that works fine, no matter what characters I throw at it. This makes me believe it's less of an issue with the underlying String.