Skip to content

Instantly share code, notes, and snippets.

@justinmk
Last active November 5, 2023 20:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinmk/2980a9d95cec12d6253bff3df314f3c4 to your computer and use it in GitHub Desktop.
Save justinmk/2980a9d95cec12d6253bff3df314f3c4 to your computer and use it in GitHub Desktop.
macOS Automator script to open files in nvim from Finder

iTerm2 instructions: https://gregrs-uk.github.io/2018-11-01/open-files-neovim-iterm2-macos-finder/

Terminal.app instructions:

  1. Open Automator and create a new Application
  2. Add a Run AppleScript action and paste in the code below.
    on run {input, parameters}
        # Must use full path.
        set cmd to "/usr/local/bin/nvim "
        set filepaths to ""
        if input is not {} then
          repeat with currentFile in input
            set filepaths to filepaths & quoted form of POSIX path of currentFile & " "
          end repeat
        end if
        tell application "System Events" to set terminalIsRunning to exists application process "Terminal"
        tell application "Terminal"
          activate
          if terminalIsRunning is true then
            do script with command cmd & filepaths
          else
            do script with command cmd & filepaths in window 1
          end if
        end tell
    end run
    
  3. Save the Automator document somewhere as nvim.app
  4. (Optional) Drag nvim.app to the Dock.
  5. Find a .txt file (for example) and view its info (CMD-i).
    • In the Open with: menu, select nvim.app.
    • Also click Change All… to apply to all *.txt files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment