0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Finder, Terminal, VScode 間の移動 (Mac)

Last updated at Posted at 2023-02-24

Finder, Terminal, VScode 間をパッと移動したいことがよくあると思います。そのための方法を以下にまとめました。

  1. Terminal から Finder
  2. Finder から Terminal
  3. Finder で開かれているフォルダに Terminal 上で移動する
  4. Finder から VScode

1 Terminal から Finder

Terminal のカレントディレクトリを Finder で開くには、open . を使います。open コマンドを使えば、他のディレクトリやファイルも開けたり、アプリを起動したりできるので便利です。

2 Finder から Terminal

ここでは、Finder 上のディレクトリを Terminal で開くためのショートカットキーを登録します。まずシステム設定から[System settings > Keyboard > Keyboard Shotcuts > Services]を開きます。

Untitled.png

そして、以下の赤枠内にチェックマークをつけ、適当なショートカットキー(ここでは Cmd + Shift + E)を登録します。
SCR-20230225-4ok.png

実際に Finder から Terminal を開くには、Finder 上でディレクトリを選択して先ほどのショートカットキーを使うか、右クリックから下の赤枠部分のどちらかを選択して開きます。
SCR-20230225-4sf.png

3 Finder で開かれているフォルダに Terminal 上で移動する

ここでは、便利なシェル関数を紹介します。Terminal を使っているときに、ちょうど Finder で開いているディレクトリに Terminal 上で移動したい場合に使います。それは以下の cdf コマンドによって実現できます。(このページから引用しました。)
使いたい方は、.zhsrc.bashrc に追加してみてください。

# Change working directory to the top-most Finder window location

cdf() {
  cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
}

例えば下の画像では、初めは Terminal 上で Desktop にいましたが、cdf を実行することで、Finder 上で開いていた Google フォルダに移動していることがわかります。
screenshot 1.png

4 Finder から VScode

Finder 上のフォルダを VScode で開きたいことは常々あると思います。そんな時に選択したフォルダをショートカットキーで開けたら便利ですよね。ここでは、Automator.app の Quick Action を使って簡単にそのショートカットキーを作ります。

まず、Automator.app を開き Quick Action を選択します。
screenshot 1.png

次に、赤枠の部分を「files and folders」in「Finder」に変更します。
screenshot 2.png

次に、左の検索ボックスで「open」を入力すると「Open Finder Items」が候補に出てくるので、それをドラッグ&ドロップで右に持ってきます。そして、その中では、VScode を選択します。
screenshot 3.png

以上の作業が完了したら、「Open in VScode」などと名前をつけて保存してください。

最後に、この Quick Action にショートカットキーを割り当てます。
システム設定を開き、[System Settings > Keyboard > Keyboard Shotcuts > Services > Files and Folders] と進んでいくと次の画面が現れ、先ほど作成した「Open in VScode」が見つかると思います。それに適当なショートカットキー(ここでは Cmd + Shift + W)を割り当てます。

screenshot.png

作業が完了したら、Finder であるフォルダを選択して、ショートカットキーを押してみてください。一発で VScode が開きましたね。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?