Action

Insert Current Date (Prompt)

Posted by @_heyjarrod, Last update almost 3 years ago

UPDATES

almost 3 years ago

Now includes a timestamp format option.

show all updates...

almost 3 years ago

Now includes a timestamp format option.

about 3 years ago

The prompt buttons now diplay the current date, formatted as they would be inserted into the draft.

about 3 years ago

Simplified adding and changing date options with a Define Template Tag step. Streamlined the script and added an error message.

Thanks to @sylumer for the suggestion in the Drafts Forum.

about 3 years ago

Updated to use Date.js so that adding and changing preferred date formats easier and more versatile for the user.

Uses the Date and Time Format Specifiers from Date.js.

about 3 years ago

Added a new script as the first step to separate out the prompt options for easy editing. This also simplifies parsing the date formats.

Inserts the current date. Opens a prompt each time to allow you to select the date format you prefer from a button list.

Date options can be added or changed in the OPTIONS tag definition step (one option per new line) using the Date and Time Format Specifiers from Date.js.

Steps

  • defineTemplateTag

    name
    OPTIONS
    template
    yyyy-MM-dd
    MMMM d, yyyy
    MM/dd/yyyy
    MM-dd-yyyy
    MM/d/yy
    MM-d-yy
    MM/dd/yyyy hh:mm:ss
  • script

    //Create prompt
    let promptDate = Prompt.create();
    promptDate.title = "Insert Formatted Date";
    draft.getTemplateTag("OPTIONS").split("\n").map(stringDateOption => promptDate.addButton(new Date().toString(stringDateOption)));
    
    //Process the prompt response
    if (promptDate.show())
    {
    	let stringDate = promptDate.buttonPressed;
    	if (stringDate != undefined)
    	{
    		//Replace selection
    		const [integerSelStart, integerSelLen] = editor.getSelectedRange();
    		editor.setTextInRange(integerSelStart, integerSelLen, stringDate);
    		//Position cursor at end of insertion
    		editor.setSelectedRange(integerSelStart + stringDate.length, 0);
    	}
    	else app.displayErrorMessage(`"${promptDate.buttonPressed}" could not be converted to a date.`);
    }
    
    //Activate editor
    editor.activate();

Options

  • After Success Default
    Notification None
    Log Level None
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.