alexchantastic / alfred-open-with-vscode-workflow

Alfred 5 workflow for opening files or folders in Visual Studio Code
MIT License
305 stars 19 forks source link

Workflow reports VSCode isn't open #9

Closed mijewe closed 5 months ago

mijewe commented 2 years ago

Since updating to OSX 12.13.1, when I run code xxx to open the xxx folder, if VS Code is already running, it doesn't open a new window.

There was no error reported, so I added a try-catch around bit that opens VS Code, so now I have

try
    tell application "Visual Studio Code"
        open theTarget
    end tell
on error errMsg
    log errMsg
end try

When I run code xxx, I now get the error "Visual Studio Code got an error: Application isn’t running."

If I close VS Code, and open a folder using this workflow, it opens successfully.

alexchantastic commented 2 years ago

Thanks for filing this! I'm trying to reproduce this on my end, but have been unable to so far.

Can you confirm that these are the steps that I should follow?

  1. Have VSCode running
  2. Run code {path_to_folder} where {path_to_folder} is a path to a folder on your system (e.g., code ~/Projects)

Also, can you confirm that you are using the v1.2.0 release?

Finally, can you share the workflow debugging output when you run the workflow and run into this error? Check out this article on how to run the debugger.

mijewe commented 2 years ago

I just tried this again and it seems like it will continue worked for a few seconds after the first folder is opened in VSCode, so I can sometimes use the workflow for a second time, but after a few seconds it will stop opening folders. Weird!

So the updated steps are:

  1. Have VSCode not running.
  2. Run code {path_to_folder}
  3. (see that it opens VSCode correctly)
  4. Run code {path_to_folder_2}
  5. (if you're fast enough, it will open properly)
  6. Run code {path_to_folder_3}
  7. See that nothing happens.

There was no output from this before I added the above try-catch. With the error logging added, it looks like this:

[13:53:35.730] Visual Studio Code[File Filter] Processing complete

[13:53:35.731] Visual Studio Code[File Filter] Passing output '[folder1]' to Run Script
[13:53:54.342] Visual Studio Code[File Filter] Processing complete

[13:53:54.343] Visual Studio Code[File Filter] Passing output '[folder2]' to Run Script
[13:53:54.508] STDERR: Visual Studio Code[Run Script] Visual Studio Code got an error: Application isn’t running.
[13:54:03.040] Visual Studio Code[File Filter] Processing complete

[13:54:03.042] Visual Studio Code[File Filter] Passing output '[folder3]' to Run Script
[13:54:03.207] STDERR: Visual Studio Code[Run Script] Visual Studio Code got an error: Application isn’t running.
alexchantastic commented 2 years ago

Very strange! Unfortunately, I'm still not able to reproduce this on my end.

I did notice that your debugging output states that you are using the Visual Studio Code[File Filter] action which is linked to the codef keyword rather than code. Did you happen to modify the workflow at all?

mijewe commented 2 years ago

I've uninstalled and reinstalled the workflow so it's as was.

I'm getting the same issue with both the codef and code inputs - VSCode opens the first time, but not on subsequent times.

Adding in the try-catch I get the same "Application isn't running" error message

14:54:09.593] Visual Studio Code[File Filter] Passing output '[folder]' to Run Script
[14:54:09.758] STDERR: Visual Studio Code[Run Script] Visual Studio Code got an error: Application isn’t running.
[14:54:18.624] Visual Studio Code[File Filter] Processing complete

[14:54:18.625] Visual Studio Code[File Filter] Passing output '[folder]' to Run Script
[14:54:18.792] STDERR: Visual Studio Code[Run Script] Visual Studio Code got an error: Application isn’t running.
[14:54:49.658] Visual Studio Code[Keyword] Processing complete

[14:54:49.661] Visual Studio Code[Keyword] Passing output '[filepath]' to Run Script
[14:54:49.838] STDERR: Visual Studio Code[Run Script] Visual Studio Code got an error: Application isn’t running.

and I'm on Alfred 4.6.4

Thanks for your help btw

alexchantastic commented 2 years ago

Unfortunately, I'm still unable to reproduce this. Trying to figure out if there is anything different that I'm doing or if there's something different in our environments.

What version of macOS are you running on and what version of VS Code are you using?

Also trying to rule out an issue with the script or AppleScript itself. What happens if you run the following script in Script Editor.app?

set theTarget to "{FULL_PATH_TO_FOLDER}"
tell application "Visual Studio Code"
    open theTarget
end tell
catch6 commented 2 years ago

I reproduce this on my m1 pro mac

  1. Have VSCode not running.
  2. Run code {path_to_folder} (see that it opens VSCode correctly)
  3. Run code {path_to_folder_2}
  4. See that nothing happens.
image
alexchantastic commented 2 years ago

@catch6 thanks for confirming this bug. Unfortunately, I am still unable to reproduce this on my various macOS machines. Can you run through some of the questions I asked earlier in this thread?

What version of macOS are you running on and what version of VS Code are you using?

Also trying to rule out an issue with the script or AppleScript itself. What happens if you run the following script in Script Editor.app?

set theTarget to "{FULL_PATH_TO_FOLDER}"
tell application "Visual Studio Code"
    open theTarget
end tell
catch6 commented 2 years ago

@alexchantastic

set theTarget to "{FULL_PATH_TO_FOLDER}"
tell application "Visual Studio Code"
    open theTarget
end tell

in Script Editor.app is working as expected

alexchantastic commented 5 months ago

Fixed in v1.3.0