MacOS Finder New Markdown File


Apple Script that will create a new Markdown file in the current folder, copying the filename to the first line as a H1.


MacOS Finder does not have any simple ways to create new files. The following Apple Script will create a new Markdown file in the current folder (or if the user does not have permissions, on the Desktop). The script will ask for a name and set the first line the the name with a # making it a H1.

Create the Apple Script

Open Script, click on New Document to create a new document.

Paste in the following:

	tell application "Finder" to set the currentFolder to (folder of the front window as alias)
on error
	set the currentFolder to path to desktop folder as alias
end try

set newfilename to ""
(*repeat while newfilename = ""*)
display dialog "Filename?" default answer newfilename buttons {"Cancel", "OK"} default button 2
set newfilename to text returned of the result
(*end repeat*)
set currentFile to POSIX path of currentFolder & newfilename

do shell script "echo " & quoted form of "# " & newfilename & " > " & quoted form of currentFile & ".md"

(Not sure where this code originally came from, scraped it from the web ages ago, if you recognize it, let me know?)

  • Select File menu, Export
  • Set filename to New File
  • Set Where to your local Applications directory, which should be the default
  • Set File Format: to Application
If you have an Apple Developer account with a Mac Development Identity, select it in the Code Sign dropdown. This will prevent a nag screen “New File” can’t be opened because it is from an unidentified developer.

Click Save. If you want, save the source script file so you can edit it later. When done, close Script Editor.

Add to Finder Toolbar and Test

Find the New in your user’s Applications directory, Command + Click and drag the New to the Finder toolbar.

To edit the position and spacing of the toolbar button, Control + Click on the toolbar and select Customize Toolbar....

To test, navigate to a directory and click the new button on the toolbar.

Comments are closed.