Feature Request: Date Picker in Prompt for User Action

I dream for (quite) a long time of a date picker in Prompt for User Action (an easy KM general purpose GUI in fact), with immediate benefit of avoiding main date validation...

For the time being, is some HTML+Java(script) in Custom HTML Prompt Action can do some part of the job (even with European/French date :wink: )?


1 Like

There are several ways the Prompt for User Input action should be extended. Things like:

  • Multi-line Text Areas
  • Date Picker
  • Color Picker perhaps
  • New/Open File/Folder selection

Probably more. They are on the todo list, and may come at some point. Part of the purpose of the Custom HTML Prompt is to allow a lot of these to be written in the mean time - even though its much more challenging to write such things than it would be if they were native in the Prompt for User Input action.

Perhaps someone will take up the challenge and write up something that can generate custom Custom HTML Prompts. Now that would be very meta.


That would be a challenge indeed.

Meanwhile, one thing you can do to speed up form development is to use a HTML WYSIWYG Editor to develop the form, and then tweak it for KM.

I have searched high and low for such an editor on the Mac, and to my amazement I have been unable to find a really good one.

I did find a great one though: Microsoft Expressions Web.

It is a great tool, and free for the full (but unsupported) version.
Of course, it only runs on Windows.

Fortunately, I have Windows on my Mac via Parallels Desktop VM. :sunglasses:

The best Mac Editor I have found is Blue Griffion. It is pretty good, but not nearly as good, as intuitive, as MS Expressions Web.

If anyone know of a great Mac HTML WYSIWYG Editor, please let me (and everyone here) know.


Hey Alain,

This AppleScript requires OSX 10.11 (El Capitan).

I don't know if Keyboard Maestro can be made to run it natively (Peter?), but you can save it as an applet and launch the applet from Keyboard Maestro then return the date to a Keyboard Maestro variable.

You can try it out by running in in the Script Editor.app โ€“ you MUST use โŒ˜^R to โ€œRun in Foregroundโ€.


# Author: Shane Stanley
use AppleScript version "2.3.1"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set theApp to path to frontmost application as text

if not (current application's NSThread's isMainThread()) as boolean then
	display alert "This script must be run from the main thread." buttons {"Cancel"} as critical
	error number -128
end if
-- create a view
set theView to current application's NSView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 200))
-- create date picker
set datePicker to current application's NSDatePicker's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 100))
-- set style: choices are NSTextFieldAndStepperDatePickerStyle, NSClockAndCalendarDatePickerStyle, or NSTextFieldDatePickerStyle
datePicker's setDatePickerStyle:(current application's NSClockAndCalendarDatePickerStyle)
-- set elements: choices include NSHourMinuteDatePickerElementFlag, NSHourMinuteSecondDatePickerElementFlag, NSTimeZoneDatePickerElementFlag, NSYearMonthDatePickerElementFlag, and NSEraDatePickerElementFlag
datePicker's setDatePickerElements:((current application's NSYearMonthDayDatePickerElementFlag) + (current application's NSHourMinuteSecondDatePickerElementFlag as integer))
-- set initial date
datePicker's setDateValue:(current application's NSDate's |date|())
-- get the size it needs
set theSize to datePicker's fittingSize()
--resize the picker and view accordingly
theView's setFrameSize:theSize
datePicker's setFrameSize:theSize
-- add the picker to the view
theView's setSubviews:{datePicker}
-- create an alert
set theAlert to current application's NSAlert's alloc()'s init()
-- set up alert
tell theAlert
	its setMessageText:"Pick a date"
	its setInformativeText:"Any date"
	its addButtonWithTitle:"OK"
	its addButtonWithTitle:"Cancel"
	its setAccessoryView:theView
end tell

-- show alert in modal loop
set returnCode to theAlert's runModal()
if returnCode = (current application's NSAlertSecondButtonReturn) then error number -128
-- retrieve date
set theDate to datePicker's dateValue() as date

Thanks Peter for your encouraging answer.

Perhaps something as this standalone HTML / JS date-picker, I collect from code.jquery.com, can bootstrap such a challenge :wink:

:beer: code.jquery.com--date-picker-js-local-fr.html.zip (234.1 KB)


1 Like

Thanks a lot Christopher to answer with an AppleScript code of Shane Stanley (perhaps you adapt) :grinning:

Even if I am still running OS X 10.10.5 Yosemite, it was hard to resist to give a try :wink:

I was first locked by the statement

AppleScript cannot coerce datePicker's dateValue() to be a date (don't know if it is due to Yosemite).

Nevertheless, some Googling and do-it-yourself leads to a solution with help of Shane Stanley anew :grinning:

I even manage to test ability to preset initial date to a given one and use a more compact display

Here is the Yosemite working starting point demo to a more sophisticated code needed to be actually usable
:beer: date-picker-yosemite-preset.applescript.zip (1.5 KB)

Another good new is this text code with extension ".applescript" can run within KM using simple Execute action

I have two more questions to kind Object C specialists:

  • How to display
    01/04/2016 in place of 1/ 4/2016?
  • How to make โ†‘ โ†“ to increment/decrement within KM... as it works nicely outside?


1 Like

I'm new to coding, when I try and run your code I get the following error

zScreen Shot 2021-06-15 at 10.33.07 PM

Following that link now gives " We're sorry, this download is no longer available."

It's now available here from the Internet Archive Wayback Machine: https://web.archive.org/web/20170610184017/http://download.microsoft.com/download/F/D/8/FD88D81D-52B5-486A-A53F-CCDB485D5258/Web_Trial_en.exe

Hey Leland,

Did you run it from a Execute an AppleScript action?

Or as I state above โ€“ as an AppleScript applet?


I got it to work! Yes, I was saving it as an AppleScript not saving it as an Application. Thank you for the clarification :), I didn't quite understand when I read it above.

1 Like