Make A Date for Keyboard Maestro

Inserts a date expanded from natural language when >>date string< is typed.

Setup

  1. Unzip the archive and open the folder in Finder
  2. Move the file makeadate.js to a location on your hard drive where it can be referenced
  3. Install the .kmmacros file in Keyboard Maestro
    • Modify the Execute JavaScript for Automation action, selecting the location of makeadate.js
    • Optionally, modify the default date and time format variables (dateFormat, timeFormat)

For the record, this script includes the entire Sugar.js library for handling the natural language. It was too much script to put into the KM editor, so placing it in an external file was the easiest solution.

Usage

To start converting a date (with the macro enabled), type >>, then an optional format shortcut and modifiers, and the natural language version of the date and/or time. Type < at the end of the string and Keyboard Maestro will run the script, replacing the entire string (including >> and <) with the result. If the string isn’t parseable, the original is returned.

Natural language

You can type dates in many basic formats. Whether it’s absolute (e.g. “Nov 5 3pm”) or relative (e.g. “in 20 minutes”), most phrasings will work as long as the language doesn’t get too complex.

To create a relative date type >>tomorrow< (or just tom), or >>in 3 days<. Add a time to it using 3pm or 3:30 pm (or any permutation). Create an absolute date by using a month and day, optionally a year and time: >>jul 19 1978<, or >>n 7/19/78 6am< to get “Wednesday, July 19th at 6:00 AM.”

Increments and shortcuts

When using relative times, you can increment and decrement by typing “in 3 days” or “3 days ago,” but you can abbreviate these with m, h, d, y, days, months, years, and min(utes). A number followed by one of these will increment the current time by that amount, and preceding with a minus symbol (-3d) will decrement. Note that 3m is three minutes not months. To perform relative date calculation using months, you have to type the word out, e.g. -3 months.

Formats

Common formats:

  • f: fullSaturday, November 12, 2016 12:00 AM
  • l: longNovember 12, 2016 12:00 AM
  • m: mediumNovember 12, 2016
  • n: nice (ordinal date, “at” for time)Saturday, November 12th at 3:00 PM
  • N: nice with yearSunday, November 13th, 2016 at 3:00 PM
  • s: short11/12/2016

Special:

  • d: hyphenated date only2016-11-13
  • i: ISO timestampSat Nov 12 2016 3:00 PM
  • t: time (12hr)06:30 PM
  • T: time (24hr)16:30
  • U: unix timestamp (milliseconds)1478984400000
  • u: unix timestamp1478984400
  • x: localized date/time stringSat Nov 12 2016 1:20 PM

Examples

Examples created on 2016-11-12

  • Today:

    >>today< or >>tod<2016-11-12

  • Tomorrow:

    >>tomorrow< or >>tom<2016-11-13

  • Relative date and time:

    • >>5 days<2016-11-17
    • >>5d<2016-11-17
    • >>5 days ago<2016-11-07
    • >>-5d<2016-11-07
    • >>15m<2016-11-12 12:10pm
    • >>15m ago<2016-11-12 11:40am
    • >>-30m<2016-11-12 11:25am
  • Next Wednesday:

    >>wednesday<2016-11-16

  • Most recent Wednesday:

    >>- wednesday<2016-11-09

    “last” skips to previous week: >>last wed<2016-11-02

  • Absolute date:

    >>sep 25<2016-09-25

    >>sep 25 1965<1965-09-25

    >>sep 25 2017 3pm<2017-09-25 3:00pm

  • Relative date, absolute time:

    >>3p tom<2016-11-13 3:00pm

  • Full date format:

    >>f sept 25 1965<Saturday, September 25, 1965 12:00 AM

  • “Nice” format with time:

    >>n 3p tom<Sunday, November 13th at 3:00 PM

  • ISO timestamp:

    >>i now<Sat Nov 12 2016 1:19 PM

Date format

The format string uses strftime parameters and LDML tokens, which can be combined. See https://sugarjs.com/dates/#/Formatting for more information.

Time format

By default, if no time is specified in natural language, the output date in most formats will not include it. If an input string includes a time, the format specified in the timeFormat variable will be appended to the date format. This doesn’t apply to full, date-only (d or m),

Rounding times

You can include r after or instead of a format shortcut to round times to the nearest half hour. If you add a number to it, you can change the amount that it rounds (r60 to round to the nearest hour). This modifier should come after any format shortcuts: >>lr30 in 4 hours<.

Why? Because most of the time when I write “in 2 hours” I don’t mean to the minute. At 12:36PM, I wanted “2 hours” to be 2:30PM.

Past/Future

If a string contains a weekday name or 3-letter abbreviation and does not include the words “last” or “ago”, future dates will automatically be forced. Thus typing “wed” will always assume you mean next wed by default.

You can include a - (minus symbol) at the beginning (or immediately after a format option and modifiers), followed by a space to force allow past dates when they’re deemed appropriate. So >>- thursday would allow it to return the most recent thursday instead of forcing it to find the next one. If using a format option and/or modifiers, it must come at the end: >>lr30- thursday<.

Download

Make A Date for Keyboard Maestro v1.0.1

A Keyboard Maestro macro that expands a date using natural language

Published 11/12/16.

Updated 11/17/16. Changelog

DonateMore info…

Related Projects