Open anything in VS Code using a MacOS quick action

Jim Bennett | Dec 13, 2018

I’ve been getting fed up with the long winded process to open things in VS Code - you know, typing in the terminal, opening VS Code and dragging folders in, that sort of long, manual process… #FirstWorldProblems 😜

I thought it would be fun to automate the whole thing, using Automator!

If you haven’t used Automator, it’s a great little tool. You can build simple workflows using capabilities from system apps and other apps, configure the data that comes in, then trigger these when things happen, such as calendar events, items changing in a folder or on demand.

These workflows can be wired up to “Quick Actions”, these are actions that can be applied to text or images and are called from the context menus in Finder or in a text box. They can also be launched from a keyboard combination or the touch bar.

Creating a Quick Action to open VS Code

The first step is to create a quick action to open VS Code.

  • Launch Automator
  • Create a new Quick Action

  • Configure the workflow:
    • Set it to receive current “files and folders” from Finder.
    • Set and image if you want one - I used the icons from this GitHub repo.
  • Add a new Run Shell Script action to the workflow.
    • Set the Pass Input to be “as arguments”
    • Set the shell script to be:
open -n -b "" --args "$*" 

  • Save the action using a name like Open In VS Code.

This will register the quick action with Finder, and you will now be able to right-click on a file or folder in Finder and select Quick Actions->Open In VS Code

Adding a keyboard shortcut

Keyboard shortcuts can be added to Quick Actions from System Preferences.

  • Launch System Preferences
  • Open the Keyboard settings and select the Shortcuts tab
  • Select Services from the list on the left
  • Scroll down on the right to Files and Folders->Open In VS Code
  • Click the none keyboard shortcut and press the keys you want to use

Adding to the touch bar

If you are a fan of the touch bar (and I am, and I know it’a a controversial opinion), you can add quick actions there. Unfortunately not on an action-by-action basis, but you can add a button that shows the quick actions.

  • From the Keyboard settings in System Preferences, select the Keyboard tab.
  • Click Customize touch bar…
  • Drag the Quick Actions button down to the touch bar and position it where you want. For mine I replaced the default Siri button with the quick actions button as I’ve never used Siri on my Mac.
  • Click Done

You will now have a quick actions button on the touch bar, and when you tap it it will show you the Open in VS Code action. If you change the color of the quick action in Automator it will change the color of this button!

More shortcuts…

Once I started with this, I added one to open a folder in terminal, and will probably add a load more for things like git commands.