ttscoff / bunch

Documentation repository for Bunch.app
https://bunchapp.co
116 stars 5 forks source link

Visual Studio Code workaround failing #315

Open jgclark opened 10 months ago

jgclark commented 10 months ago

https://bunchapp.co/docs/troubleshooting/#visual-studio-code indicates that VSCode is problematic, but that you have kindly implemented a hard-code workaround.

That doesn't seem to be working for me, at least on bunch 1.4.16 (177) / macOS 13.6.3 / VSCode 1.85.2.

For

Visual Studio Code
- XX      # i.e. just trying to close all windows

the log says

2024-01-26 13:17:34: 🔴[Test-VSC] {
    NSAppleScriptErrorAppName = "System Events";
    NSAppleScriptErrorBriefMessage = "Can\U2019t get process \"Visual Studio Code\".";
    NSAppleScriptErrorMessage = "System Events got an error: Can\U2019t get process \"Visual Studio Code\".";
    NSAppleScriptErrorNumber = "-1728";
    NSAppleScriptErrorRange = "NSRange: {0, 0}";
}

I have also tried with the following variations, none of which work.

VSCode
com.microsoft.VSCode%
com.microsoft.VSCode

(The middle one is apparently is its bundleID, with the %. But I tried without as well.)

jgclark commented 10 months ago

PS: This is a workaround: $ code ~/GitHub/NotePlan-plugins/NotePlan-plugins.code-workspace

But it means I lose some of the other helpful features of app control at start/end of bunches.

00dani commented 5 months ago

The trailing % isn't actually part of VS Code's bundle ID - it's a quirk/feature of Zsh, the default shell in current MacOS. When you run a command that outputs text with no trailing newline, like mdls -r, Zsh marks the final line with a % sigil so you can tell there was no trailing newline. The bundle ID really is just com.microsoft.VSCode.

Of course, that doesn't explain why com.microsoft.VSCode\n- XX isn't working. I've done some testing of my own, and it looks like Bunch is having trouble pulling out and using the bundle ID when given the XX instruction. I can't see the AppleScript it's running behind the scenes, but my guess is that it's trying to tell process "com.microsoft.VSCode" rather than tell application id "com.microsoft.VSCode".

⚪[Close] Closing all com.microsoft.VSCode windows
🔴[Close] {
    NSAppleScriptErrorAppName = "System Events";
    NSAppleScriptErrorBriefMessage = "Can\U2019t get process \"com.microsoft.VSCode\".";
    NSAppleScriptErrorMessage = "System Events got an error: Can\U2019t get process \"com.microsoft.VSCode\".";
    NSAppleScriptErrorNumber = "-1728";
    NSAppleScriptErrorRange = "NSRange: {0, 0}";
}

Unfortunately, however, I don't think there's a way to fix this and get XX to work with Code, because Code itself doesn't understand the AppleScript command close every window even when it's sent in the correct way:

tell application "System Events"
  tell application id "com.microsoft.VSCode"
    close every window
  end tell
end tell
-- Visual Studio Code got an error: every window doesn’t understand the “close” message. (-1708)
ttscoff commented 5 months ago

I'll have to dig in and see if I'm using process or application id, but I don't think VSCode is going to respond to close all windows either way (it's not a standard macOS app with a scripting definition).

The hardcoded workaround may be trying to fix a problem that doesn't exist anymore if VS Code has actually fixed the issue where it needed one app name to start (Visual Studio Code) and then another app name (Code) once it was running. I'll take a look at that when I get time.