Easy README Files on Your Mac
Jan 28, 2015
This article will show a way to set up an easy keystroke command to create a new README text file in the selected folder (if it doesn’t already exist), and open it for editing in your favorite text editor (iA Writer used in my example).
If you are like me, working on various projects throughout the day, you might want an easier way of documenting important notes. Instead of opening up a text editor, and either navigating to the folder where you want the file saved, or saving it and moving it to the right folder at a later time, sometimes just those few extra seconds seem enough of a nag that the notes are put off until they are eventually forgotten.
In this article, we’ll go over two ways to make this process easy, both through the GUI and through the Terminal. The text editor I am referencing in my examples is iA Writer, but you should be able to substitute that for your favorite text editor.
Setting up a service to create new README file in the selected folder and open it for editing in iA Writer.
Following these steps will allow you to automatically create a README file in a selected folder, and open it for editing in iA Writer.
First, open Automator, and create a new Service.
Next, Drag the “Run Shell Script” action to add it to the workflow. Delete any pre-populated text, and put the following lines:
Change the dropdown beside “Service receives selected” to be “folders” as the chosen object, and select “Finder” in the accompanying dropdown.
Finally, select the option for the dropdown labeled “Pass input:” to be “as arguments.”
It should look similar to this:
Save the action and give it a descriptive name that will mean something to you (ie. “Create new README”). This will be what is displayed in the services menu if you right-click on a folder.
The location of the file created by Automator is:
Create a keyboard shortcut to access the new folder service
At this point, the service should be accessible if you right-click on any folder and choose Services -> “Create new README” (or whatever you named your service). Clicking that should create a new file named README.md and open it in iA Writer, or simply open the file in iA Writer if it already exists in the folder.
However, wouldn’t it be much nicer to be able to simply use a keyboard shortcut to do the same thing? Now that we have the service created, it is just a matter of assigning a shortcut of your own choosing to accomplish that.
First, open System Preferences, and choose Keyboard. Select the Shortcuts tab, and choose Services in the left-hand menu. Now, scroll down to the “Files and Folders” section and you should see your new service listed there. Click it to highlight it, and then click “add shortcut” and type the keystroke you want to use to access it anytime a folder is selected. I chose CTRL-Command-R for mine.
Create a shortcut to do the same thing at the command-line in Terminal
This bash script is designed to make opening a file in iA Writer on the Mac from the Terminal command-line easy.
Once set up, running “ia README” at the command-line will open the file if it exists, exactly as the name is specified with no extension. Otherwise, it will create a new file called README.md with the md file extension, if it doesn’t already exist, and open it. If a file called README.md does already exist, it should be safely opened without being overwritten.
To implement this in your Terminal:
First, open Terminal and navigate to your home directory (“cd ~/”). Now open the .bash_profile file for editing (“nano .bash_profile”).
Finally, add either of the two options below to your .bash_profile file in your user directory (~/).
OPTION 2: SINGLE LINE EXAMPLE
At this point, you should be set up and ready to go.