Apple - OSX: how to add a right click option to a folder which opens the folder with an app like VS Code?
You can do this with an Automator Service.
Create the Service:
Open Automator and select Service or File > New > Service If Automator is already open.
Set Service receives selected to files or folders and in to Finder.
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
- Save the Service as Open in Visual Studio Code.
- 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.
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
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:
- Open Automator
- File > New
- Select Quick Action
- Click Choose
- Select "Workflow receives current files or folders in Finder"
- From the left hand side pane in Automator, drag-drop Library > Utilities > Run Shell Script into the right hand pane
- Ensure Pass input is set to "as arguments"
- Then paste the below text:
for f in "$@"; do
open -a 'Preview' "$f"
done
- Click File > Save
- Give name as "Open in Preview"
- Go to Finder, select a folder containing PDF files, right click on folder name in finder > choose Quick Actions > Open In Preview
- 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.