fabiospampinato / vscode-open-in-application

Open an arbitrary file in its default app, or the app you want.
MIT License
19 stars 0 forks source link

Need more information about configuration #1

Closed realB12 closed 6 years ago

realB12 commented 6 years ago

Hi Fabio, I am trying to open all *.md Files with Typora Editor. I have tried the following setting: "openInApplication.applications": { "md": [ "C:\Program Files\Typora\Typora.exe" ] // Ask which application to use when opening html files }

does not work in a sense that when I rightclick an *.md file and choosing "Open in Application" - nothing is happening. I am working with newest version of vs code on a most actual windoows 10 maschine. Any suggestions?

fabiospampinato commented 6 years ago

@realB12 if you always want to open markdown files with Typora you don't need to use an array in your configuration, something like this would be better:

"openInApplication.applications": {
  "md": "C:\Program Files\Typora\Typora.exe"
}

We use the open package under the hood for opening application, which in turns uses an utility called start in Windows. If running start MY_APP in the terminal works you should be able to use MY_APP in this extension's configuration.

I think the problem with your configuration is that you forgot to double escape the string, Windows has its quirks, one of them is that it uses a backslash (\) for separating paths, but \ is generally used as an escape character, so you have to escape that in your string if you actually want to type a backslash. Basically in this case you'll have to change "C:\Program Files\Typora\Typora.exe" to "C:\\Program Files\\Typora\\Typora.exe".

tjx666 commented 4 years ago

Still doesn't work after escape the path.

tjx666 commented 4 years ago

Snipaste_2019-12-11_11-25-33

It seems that applications written using electron all have this problem. Typora and mark text all written using electron, they all don't work, but the IDEA works well.

https://github.com/sindresorhus/open/issues?utf8=%E2%9C%93&q=is%3Aissue+electron

fabiospampinato commented 4 years ago

@tjx666 Electron applications have to explicitly add support for opening files directly like that, maybe those apps haven't added support for this? I'm not sure.

WangHeng93 commented 4 years ago

Get from Open in External App - Visual Studio Marketplace

2. VSCode extension API: vscode.env.openExternal(target: Uri)

This API has one limit that can't open file path which includes Non-ascii characters, but support open file in application which is made by electron. This API can only pass one argument target, so openCommand and args configuration item is not work.

If you want to open file in application which is made by electron, you can choose one of two ways:

  1. don not config it in VSCode settings, and set the default application of your operation system to open that file format.

  2. using isElectronApp option:

    {     "extensionName": "md",     "isElectronApp": true,}

    multiple apps example:

    {     "extensionName": "md",     "apps": [         {             "title": "typora",             "isElectronApp": true,             // following config item is not work             // "openCommand": "/path/to/typora.exe",             // "args": ["--slient"]         },         {             "title": "idea",             "extensionName": "md",             "openCommand": "/path/to/idea.exe",             "args": ["--slient"],         }     ] }