Doubleclick to open a file in VIM from OSX
I use VIM for just about everything from note taking to coding to keeping track of my recipes.
Of course I've dabbled with other text editors, but nothing I've liked so far.
But I found myself more and more dealing with a txt file inside Mac's Finder app and then dropping to a terminal and spending time switching directories over to that file to edit it.
I wanted to just double click on the txt file and have it automatically open in VIM inside my iTerm. This functionality isn't built into OSX but with just a bit of Applescript we can make it work for us.
Example:
Here's what we're going to do...
- Step #1 - Open your Automator application on your Mac
- Step #2 - Build an Applescript application to launch VIM
- Step #3 - Associate your new app with files you want to open with VIM via doubleclick
- Step #4 - Try it out!
Step #1 - Open your Automator application on your Mac
Find the "Automator" app in your Applications folder and launch it.
Step #2 - Build an Applescript application to launch VIM
Choose the "Application" type and click "Choose"...
Double click on "Run Applescript"...
Copy and paste the following Applescript code...
on run {input, parameters}
set filename to POSIX path of input
set cmd to "clear && 'vim' '" & filename & "' && exit"
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text cmd
end tell
end tell
end run
Into the applescript window...
Save the Automator script as a new application in your Applications folder...
Step #3 - Associate your new app with files you want to open with VIM via doubleclick
Now find a file of whatever type you want to associate with opening in VIM. I'm doing .txt files for this example.
Right click on the file and click "Get Info"...
Now set your new .app file to be used whenever that file type is opened...
Step #4 - Done! Try it out
Now when you doubleclick on one of your .txt files, it will be opened in VIM in your iTerm terminal...
Hopefully this has been helpful for you. If you've tried out the code here, drop me a tweet at twitter.com/mattccrampton and let me know.
To: @mattccrampton
0
Other Posts
When exporting photos from a service like Flickr, perhaps after they've given notice that they're going to delete our photos if you don't subscribe to......
All Truthy and Falsy Javascript Values In Nodejs, every value has an associated boolean, true or false, value. For example, a null value has an......
Google Forcing Nest Cameras Visual Indicator Light To Be On Received the following email from Google today... Full email text... Recently, we shared our commitment......
Posting to Twitter with Python - Part Two: Posting Photos NOTE: This is part two of my posting to Twitter with Python tutorial. If you......
Sign Into Gmail Without Signing Into Google Chrome Unfortunately, Google has made changes to Chrome since this blog post was posted which removed the options......
Four Steps To Write An AppleScript to Gather ALL Windows on OSX I have no idea why, but there is no built-in way to gather......