I prefer to browse files using Finder, but to open text files using command-line Neovim (well, in fact I prefer Helix…).
I found the following Automator script and it kinda works but not faultlessly.
on run {input, parameters}
set filename to quoted form of POSIX path of input
set cmd to "clear;cd `dirname " & filename & "`;nvim " & filename
tell application "iTerm"
tell the current window
create tab with default profile
tell the current session
write text cmd
end tell
end tell
end tell
tell application "System Events"
tell process "iTerm2"
set frontmost to true
end tell
end tell
end run
- Open Automator
- Select to create an application
- Locate “Run AppleScript” and double-click it
- Paste this script, save it to
/Applications
- Select a file type of your choice, e.g.
txt
one, press Command-I, change “Open with” to your application, click “Change All” - Double-click any
.txt
file in Finder. It will be opened in iTerm2
Apart from I would prefer to use native Terminal instead of iTerm2, there is a bug:
Steps to reproduce:
- Open iTerm2
- Close the window, but don’t quit the app itself
- Double-click a
.txt
file. You will get the following error:
How it can be fixed?