Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add a command to Finder services in Mac OSX to open a folder in VS Code
- Open Automator
- File -> New -> Service
- Change "Service Receives" to "files or folders" in "Finder"
- Add a "Run Shell Script" action
- Change "Pass input" to "as arguments"
- Paste the following in the shell script box: open -n -b "com.microsoft.VSCode" --args "$*"
- Save it as something like "Open in Visual Studio Code"
@tungdmctv

This comment has been minimized.

Copy link

@tungdmctv tungdmctv commented Feb 7, 2017

Cool !!

@cnstntn-kndrtv

This comment has been minimized.

Copy link

@cnstntn-kndrtv cnstntn-kndrtv commented Mar 28, 2017

@alexadam819

This comment has been minimized.

Copy link

@alexadam819 alexadam819 commented Apr 20, 2017

Thank you!

@maheshstms

This comment has been minimized.

Copy link

@maheshstms maheshstms commented Apr 23, 2017

Thanks :)

@blackie1019

This comment has been minimized.

Copy link

@blackie1019 blackie1019 commented May 6, 2017

Awesome ! thanks!

@aditya-kanekar

This comment has been minimized.

Copy link

@aditya-kanekar aditya-kanekar commented May 15, 2017

Thanks! Thats really convenient and I learnt a new tool today.

@jaxon23

This comment has been minimized.

Copy link

@jaxon23 jaxon23 commented May 21, 2017

Rock on!

@harshadbankar

This comment has been minimized.

Copy link

@harshadbankar harshadbankar commented Jun 12, 2017

Awesome!

@tonysneed

This comment has been minimized.

Copy link
Owner Author

@tonysneed tonysneed commented Jun 19, 2017

@cnstntn-kndrtv thanks!

@bharathnayak03

This comment has been minimized.

Copy link

@bharathnayak03 bharathnayak03 commented Jul 20, 2017

Thanks

@rondabergman

This comment has been minimized.

Copy link

@rondabergman rondabergman commented Aug 22, 2017

Exactly what I was looking for! Thanks!

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Sep 2, 2017

thanks

@brunosilvano

This comment has been minimized.

Copy link

@brunosilvano brunosilvano commented Oct 4, 2017

Thanks! Was struggling to find out how to do that for a while. Your solution works like a charm.

@ogzA

This comment has been minimized.

Copy link

@ogzA ogzA commented Oct 6, 2017

I could open Visual Studio Code from terminal with "code ." but I needed that too. Thanks, that you have saved my life 👍

@lobodpav

This comment has been minimized.

Copy link

@lobodpav lobodpav commented Jan 4, 2018

The service can be further simplified this way. No need to execute a shell script.
service

@lobodpav

This comment has been minimized.

Copy link

@lobodpav lobodpav commented Jan 4, 2018

The App to be dragged into Finder's toolbar is also super easy to create.
app

Also, you can easily add VSCode icon to the Automator App so that it looks nice in Finder's toolbar - Cmd+I the VSCode and Automator app, click the VSCode icon and press Cmd+C. Then click the Automator App icon and press Cmd+V.
vscodecmdi
workflowcmdi

Once done, just drag&drop the Automator App onto Finder's toolbar while holding Cmd key. Final result looks like this.
finder

@sozercan

This comment has been minimized.

@rasikag

This comment has been minimized.

Copy link

@rasikag rasikag commented Feb 18, 2018

Cool!

@monsieurkayode

This comment has been minimized.

Copy link

@monsieurkayode monsieurkayode commented Mar 1, 2018

Nice, works like a charm

@jaltin

This comment has been minimized.

Copy link

@jaltin jaltin commented Mar 9, 2018

Thanks, really useful!

@Devtronyx

This comment has been minimized.

Copy link

@Devtronyx Devtronyx commented Mar 11, 2018

Thanks!

@apltola

This comment has been minimized.

Copy link

@apltola apltola commented Apr 1, 2018

Nice! Thanks!

@Dewiidar

This comment has been minimized.

Copy link

@Dewiidar Dewiidar commented Apr 19, 2018

Thanks so much! Works like a charm!

@RonHouben

This comment has been minimized.

Copy link

@RonHouben RonHouben commented Jun 19, 2018

Thanks for this, very helpful and easy setup!

@mattwaler

This comment has been minimized.

Copy link

@mattwaler mattwaler commented Jun 21, 2018

Everybody, you can just go to applications and cmd+click VS Code's application onto the top bar, which will allow you to drag folders onto it to open them into VSCode. No automator necessary. This also works for iTerm2.

Like This

@justcaldwell

This comment has been minimized.

Copy link

@justcaldwell justcaldwell commented Jul 13, 2018

Thanks @mattwaler! Great tip.

@mauriciogzrs

This comment has been minimized.

Copy link

@mauriciogzrs mauriciogzrs commented Jul 29, 2018

Thanks so much, @tonysneed && @lobodpav !
Is there a a way to add it to the menu when you click on the blank space (inside a folder)??

BTW, thanks you too, @mattwaler !

@JosKas

This comment has been minimized.

Copy link

@JosKas JosKas commented Aug 25, 2018

<3

@j-monteiro

This comment has been minimized.

Copy link

@j-monteiro j-monteiro commented Sep 3, 2018

really cool, ty!

@ivonakov

This comment has been minimized.

Copy link

@ivonakov ivonakov commented Sep 7, 2018

Awesome ! Thanks so much!

@siddharth2010

This comment has been minimized.

Copy link

@siddharth2010 siddharth2010 commented Sep 11, 2018

This is just great!! Awesome!

@mehdico

This comment has been minimized.

Copy link

@mehdico mehdico commented Sep 27, 2018

Very useful ! Thanks 👍

@Acovid

This comment has been minimized.

Copy link

@Acovid Acovid commented Oct 2, 2018

Thank you @mattwaler! This is just what I needed.

@Technicali

This comment has been minimized.

Copy link

@Technicali Technicali commented Oct 10, 2018

Brilliant - thanks

@gazdagergo

This comment has been minimized.

Copy link

@gazdagergo gazdagergo commented Oct 17, 2018

Cool stuff, thanks. Just to mention the poor man's method is this:
ezgif-4-82afa14a2e7d

@naviat

This comment has been minimized.

Copy link

@naviat naviat commented Jan 23, 2019

@lobodpav Thanks

@shimaaMendel

This comment has been minimized.

Copy link

@shimaaMendel shimaaMendel commented Jan 23, 2019

I have made this for myself
https://github.com/cnstntn-kndrtv/open-in-buttons-for-finder-toolbar

@cnstntn-kndrtv I got this error when trying to open in VScode
The action “Run Shell Script” encountered an error: “-: /usr/local/bin/code: No such file or directory
-: /usr/local/bin/code: No such file or directory”

@telefonosuci

This comment has been minimized.

Copy link

@telefonosuci telefonosuci commented Jan 30, 2019

Great!

@JARVIS-AI

This comment has been minimized.

Copy link

@JARVIS-AI JARVIS-AI commented Feb 4, 2019

Make sure the path of script is same as your vscode path

I have made this for myself
https://github.com/cnstntn-kndrtv/open-in-buttons-for-finder-toolbar

@cnstntn-kndrtv I got this error when trying to open in VScode
The action “Run Shell Script” encountered an error: “-: /usr/local/bin/code: No such file or directory
-: /usr/local/bin/code: No such file or directory”

@JARVIS-AI

This comment has been minimized.

Copy link

@JARVIS-AI JARVIS-AI commented Feb 4, 2019

Here we have cool stuff
Great contributes
Thanks everyone

@marcopelegrini

This comment has been minimized.

Copy link

@marcopelegrini marcopelegrini commented Feb 5, 2019

for f in "$@"
do
    open -n -b "com.microsoft.VSCode" --args "$f"
done

For multiple files

@kaimdx

This comment has been minimized.

Copy link

@kaimdx kaimdx commented Feb 28, 2019

For newbies like me, the 'Service' in automator is now called 'Quick Action'. The rest of the steps work fine.

@itsthomas

This comment has been minimized.

Copy link

@itsthomas itsthomas commented Mar 1, 2019

Automator menu is changed and I cannot follow the tutorial. Can some one please update the workflow?

@quasiDigi

This comment has been minimized.

Copy link

@quasiDigi quasiDigi commented Mar 6, 2019

I works for me.
Thanks :)

@caprica-Six

This comment has been minimized.

Copy link

@caprica-Six caprica-Six commented May 8, 2019

Great!! Thanks a lot!

@kugoo109

This comment has been minimized.

Copy link

@kugoo109 kugoo109 commented Jun 20, 2019

This should solve all your problems.
https://github.com/Mortennn/FiScript

@shaltaev

This comment has been minimized.

Copy link

@shaltaev shaltaev commented Aug 4, 2019

Awesome! Thanks you very match!

@hoangnamitc

This comment has been minimized.

Copy link

@hoangnamitc hoangnamitc commented Aug 12, 2019

Awesome! Thanks bro,

Action Same for Sublime Text:
shell script box:
 /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -a "$@"

@farkroft

This comment has been minimized.

Copy link

@farkroft farkroft commented Aug 16, 2019

cool, thanks !

@ArnoutPullen

This comment has been minimized.

Copy link

@ArnoutPullen ArnoutPullen commented Aug 21, 2019

To make it even easier add a shortcut to this service Command + .
System Preferences->Keyboard->Shortcuts->Services->Open with Visual Studio Code->Add->'Command' + '.' ->Save
Now in finder select a file or folder and press COMMAND + .
Have fun :)

@gkdg

This comment has been minimized.

Copy link

@gkdg gkdg commented Oct 4, 2019

Very cool thanks!!!!

@marcokiel77

This comment has been minimized.

Copy link

@marcokiel77 marcokiel77 commented Oct 27, 2019

Thnx!

@subbu-muthusubramanian

This comment has been minimized.

Copy link

@subbu-muthusubramanian subbu-muthusubramanian commented Nov 6, 2019

Just brilliant. Thanks

@MagnusNordin

This comment has been minimized.

Copy link

@MagnusNordin MagnusNordin commented Nov 14, 2019

For newbies like me, the 'Service' in automator is now called 'Quick Action'. The rest of the steps work fine.

Thank you very much!

@philipdanielhayton

This comment has been minimized.

Copy link

@philipdanielhayton philipdanielhayton commented Nov 28, 2019

This is brill, thank you!

@elloGuy69

This comment has been minimized.

Copy link

@elloGuy69 elloGuy69 commented Dec 21, 2019

For Mojave, use the following steps

  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 -n -b "com.microsoft.VSCode" --args "$f"
done

  1. Click File > Save
  2. Give name as "Open in VS Code"
  3. Go to Finder, select a folder or files, right click > choose Quick Actions > Open In VS Code
@bthes

This comment has been minimized.

Copy link

@bthes bthes commented Jan 13, 2020

saved my day ;-) thx

@jaekookang

This comment has been minimized.

Copy link

@jaekookang jaekookang commented Jan 25, 2020

This looks super amazing. Thanks!

@JibranYousuf

This comment has been minimized.

Copy link

@JibranYousuf JibranYousuf commented Feb 24, 2020

For Mojave, use the following steps

  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 -n -b "com.microsoft.VSCode" --args "$f"
done

  1. Click File > Save
  2. Give name as "Open in VS Code"
  3. Go to Finder, select a folder or files, right click > choose Quick Actions > Open In VS Code

Worked like a charm, thank you.

@M1kep

This comment has been minimized.

Copy link

@M1kep M1kep commented May 11, 2020

Everybody, you can just go to applications and cmd+click VS Code's application onto the top bar, which will allow you to drag folders onto it to open them into VSCode. No automator necessary. This also works for iTerm2.

Like This

Feel like this one got overlooked, but is by far the best approach IMO. Thanks @mattwaler

@rustamtm

This comment has been minimized.

Copy link

@rustamtm rustamtm commented May 21, 2020

Everybody, you can just go to applications and cmd+click VS Code's application onto the top bar, which will allow you to drag folders onto it to open them into VSCode. No automator necessary. This also works for iTerm2.
Like This

Feel like this one got overlooked, but is by far the best approach IMO. Thanks @mattwaler

Oh you are hero! Simple and powerful

@kenecottle

This comment has been minimized.

Copy link

@kenecottle kenecottle commented Sep 2, 2020

This is great, thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.