Novice scripting problem - date input

I'm not an experienced scripter, and I'm trying to create a macro that inputs three variables (month, day, and year) and executes a shell script using the three. I've got it so that the command executes successfully, but the date is not correct, and I don't know enough scripting to know how to debug.

The macro is intended to create a new Day One journal entry with the input date. However, it always creates a new journal entry with the current date.

The syntax of the dayone command is:

dayone -d="dd/mm/yyyy hh:mm[AM/PM]" new

I think the problem must be in my (one-line) shell script. Can you help?

Here's the macro:


Hey John,

I don’t have Day One, so I can’t properly test this, but…

Try running as a straight shell script:

dayone -d=$(date "+%d/%m/%Y") new


1 Like

Chris, wouldn’t that just create the entry using the current date? That’s exactly what’s happening now. I want to input a custom date using Keyboard Macro variables, and I don’t know what’s going wrong.


Hey John,

I misunderstood; obviously.

Create a display text window and send the text for your shell script to it instead of an execute shell script action. Then debug your shell script text. If you can get it working in the Terminal you can get it working in KM.

I'll look at it again when I get back from an appointment.


Chris, can you tell me how to set the script to send its text to a window instead of execute? Sorry—as I said, novice scripter.


The problem is that scripts cannot use text tokens. So %Variable%Day%, which would be correct in a text token field in Keyboard Maestro, will not work in a script.

When Keyboard Maestro executes scripts, it puts the Keyboard Maestro variables into environment variables as described in the Scripting section of the documentation. So you want something like:

/usr/local/bin/dayon -d="$KMVAR_Day/$KMVAR_Month/$KMVAR_Year 12:00PM" …
1 Like

Hey John,

You have to get your shell script right, before you use the Execute Shell Script Action.

So. It's a good idea to get your command running in the Terminal, or a BBEdit Worksheet, or an Eddie Worksheet before trying to make it work in Keyboard Maestro.

According to the man page of the `dayone` command-line-tool the basic command is:

dayone -d="03/03/2011 5:30PM" < ~/Desktop/note.txt

Supposedly the date-string is parsed according to your system date preferences, so you have to make certain those are in-line.

You'll note my macro displays the generated command-line string in a text window and does NOT execute it. You should be able to paste that string into the Terminal and have it run. If it won't run then there's something wrong with the string, and you have to debug it.

If you've already gotten your command to run in the Terminal then you know what the syntax needs to look like, and you can proceed to figure out why KM isn't producing what you want it to (most often user-error).

Once you can get the string to run in the Terminal you can switch over to an Execute Shell Script Action and go to town.

Have I made myself clear?

If not - ask more questions, and I'll try to answer.


Day One { New Note with Creation Date } { Troubleshooting Version }.kmmacros (3.4 KB)

Tags: @Day_One, @dayone, @cli, @Command-Line, @Shell_Script

Hey John,

Aha! Peter’s described the main problem.

You can simplify his solution a bit by saving the entire command-line-string to 1 variable (instead of displaying text as I did) and then using that 1 variable in your Execute Shell Script Action (in the same way that Peter demonstrates).

This simplifies troubleshooting the command-string if/when things go wrong.


Success! Thank you, Peter—I knew there was something I’d missed about how to use variables in a shell command. I appreciate your help very much.

Chris, thanks for the screen shot—now I know how to make sure the shell is receiving the command I intend, which will come in handy when I make future macros of this sort. I appreciate the time you spent to teach me something.

1 Like