OSX: how to add a right click option to a folder which opens the folder with an app like VS Code?

Solution 1:

You can do this with an Automator Service.

Create the Service:

  1. Open Automator and select Service or File > New > Service If Automator is already open.

  2. Set Service receives selected to files or folders and in to Finder.

  3. Add a Run Shell Script Action, setting Shell: to /bin/bash and Pass input: to as arguments and add the following code:


for f in "$@"; do
    open -a 'Visual Studio Code' "$f"
done

  1. Save the Service as Open in Visual Studio Code.

enter image description here

  1. Close Automator.

You can now select Files and or Folders in Finder and then control-click (right-click) on them and select Open in Visual Studio Code from the Services Context Menu.

Note: I tested this with Visual Studio Code but not with Brackets as I don't have it installed. However you should be able to create one for it too in the same manner while substituting the application's name in the open command.

Solution 2:

Here is an alternative solution: instead of using the right-click menu, you could open the folder from the finder toolbar!

Please see my repo here: open-folder-with-vs-code

Solution 3:

In macOS Mojave (10.14.2), I could not find Service option in Automator. So I had to follow the below steps to open folder contents in Preview app:

  1. Open Automator
  2. File > New
  3. Select Quick Action
  4. Click Choose
  5. Select "Workflow receives current files or folders in Finder"
  6. From the left hand side pane in Automator, drag-drop Library > Utilities > Run Shell Script into the right hand pane
  7. Ensure Pass input is set to "as arguments"
  8. Then paste the below text:
for f in "$@"; do
   open -a 'Preview' "$f"
done
  1. Click File > Save
  2. Give name as "Open in Preview"
  3. Go to Finder, select a folder containing PDF files, right click on folder name in finder > choose Quick Actions > Open In Preview
  4. All the PDF files should now open in Preview.

TODO: Add checks to ensure that Preview only opens some file types (e.g. PDF etc) and not binaries etc.