Create a new post from the Desktop

The script bellow works on the latest MacOS and you can use it to open your Markdown editor and start writting:

set theResponse to display dialog "Post Title:" default answer "" buttons {"Cancel", "New Post"} default button 2 with title "New Post"

set title to (text returned of theResponse)

set slug to do shell script "echo `date '+%F'`'-" & (title & "' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g'")

set workingDir to "/Users/CHANGETHIS"

set postPath to "/content"

set postSlug to "/post/" & slug & "/index.md"

set postPathSlug to workingDir & postPath & postSlug

set shellScript to "export TITLE='" & title & "' ; cd " & workingDir & "; /usr/local/bin/hugo new " & postSlug & "; open " & postPathSlug

do shell script shellScript
2 Likes