Insert date/time with a custom keyboard shortcut

How to map a keyboard shortcut Ctrl-Shift-D to type in the date and time 2024-01-21_0953 in any application/command line.

I find myself inserting the date/time in a sortable format, typically when sharing a file with others frequently, so this page explains how to create a keyboard shortcut.

Why?

Let’s say I have a document Dummy guide.odt, which is a live document in that is getting updates. When I share this document, I will export it to PDF (to ensure it is displayed as intended on any recipient’s machine). After hitting Export as PDF, I change the filename to Dummy guide 2024-01-21_1007.pdf, by hitting the right arrow, and then Ctrl-Shift-D.

How

I’m running Kubuntu 22.04, but this should work on most X11 based Linux desktops.

  1. sudo apt install xdotool
  2. Open Settings > Workspace/Shortcuts > Custom Shortcuts
  3. Create a custom keyboard shortcut with the command xdotool type --clearmodifiers $(date +%Y-%m-%d_%H%M)
  4. Assign Ctrl-Shift-D to the new keyboard shortcut
Tags: KDE  linux 

See also

Table of Contents