2

I have recently started using Terminal.app a lot. I figured that open command will be helpful in opening files like HTML, CSS files etc.

I have tried Visual Studio Code app from Microsoft. The app itself is running fine without installation. The problem is when I use command: open -a and press tab, the app Visual Studio Code does not appear.

I wonder if there is a way to install the app correctly? I read man open command depends on LaunchServices, and I can't find a way to register the app with this service.

3

The argument(s) to open -a command can be Tab autocompleted, if you specify the path from the parent directory, e.g. open -a /Applications.

Try running the following command-line to launch Visual Studio Code from Terminal:

open -a "Visual Studio Code"

To open a file named index.html with Visual Studio Code app using open command, type:

open -a "Visual Studio Code" index.html

Please note you need to enclose the name of the app which contains spaces into double-quotes.

Additionally, quoting from the man page:

The open command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If no application name is specified, the default application as determined via LaunchServices is used to open the specified files.

The statement is referring to the case when you are attempting to open a file using the open command. To launch an app, the syntax is simply open command followed by space, followed by -a flag, another space then the name of the app (enclosed in " if the name contains spaces).

If you have not installed the app already, you should install it by copying the Visual Studio Code.app bundle into /Applications directory.

  • 1
    It's supposed to be, if you're using the -a flag, you specify the application. Example: open -a /Applications/Komodo\ Edit\ 11.app/ "foo.bar" and auto completion does work. You have to start from the path to the directory (i.e. /Applications) – Allan Jul 21 '18 at 17:18
  • Instead of having to quote an application, I prefer to use the bundle identifier with the open command, such as open -b com.apple.DiskUtility – fd0 Jul 21 '18 at 17:51
  • Thanks for help, but the reason I asked because when I use `open -a' with correctly installed apps such as VMware Fusion, I just need to tab and autocompleted suggests it for me. The problem here is some apps was made to run without installation and autocompleted not get it. – lilw Jul 21 '18 at 18:01
  • 1
    @lilw bash's autocomplete feature isn't context-sensitive by default. It doesn't know that what follows open -a is supposed to be an application name or path, it just applies its standard rules for autocompletion, which basically assume you're filling in a file path or the name of a file in the current directory. You could write a custom autocomplete rule for this situation, but it'd be a lot of work. Or, you could start with open -a /Applications/, so that standard autocomplete candidates will be apps. – Gordon Davisson Jul 21 '18 at 18:24
  • @GordonDavisson thanks for your reply, I think that might be my answer, writing a rule for it. Yeah, it is complicated. – lilw Jul 22 '18 at 4:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .