Add a timestamp anywhere with a keyboard shortcut in Linux Ubuntu

I finally settled to plain text files with the built-in text editor in Ubuntu (version 23.10 as of the time of this writing) for all my task management and note taking (aka: productivity plans and logs) after having a terrible time with tools like Notion, Obsidian and pretty much anything else that is currently out there.

One thing I miss from those tools is the ease of adding a timestamp to anywhere in my text. Here's what I've done to bring back the joy of timestamping my notes in Linux Ubuntu 23.10 (Gnome, Wayland):

1. Open Terminal and type this to install ydotool:

sudo apt install ydotool -y

2. open a plain text editor and create a new script file. I saved mine as insert_date.sh . You can call it whatever you want, as long as it ends in the extension .sh.

3. copy or type this in the shell file:

#!/bin/bash

sleep 0.1

ydotool type $(date +"%b") " " $(date +"%d") ", " $(date +"%Y") " " $(date +"%I") ":"$(date +"%M") " " $(date +"%p")

4. save the file in /usr/local/bin

5. in Terminal type: 

 sudo chmod +x /usr/local/bin/insert_date.sh

 This will add the execute permission on the file, so the script can run.

6. Now back to Linux's GUI world, navigate to Settings, Keyboard, Custom Shortcuts and add a new one. Name it however you like.

7. In the "command:" add the location of your script, such as

/usr/local/bin/insert_date.sh

8. Add your desired keyboard shortcut and save your changes.

And that's it. The above script translates to Jan 10, 2024 02:17 pm , which is the same format I use in QuickEdit Pro Android app to view and edit my text files on my Google Pixel 7 phone and Samsung Tab S7 FE tablet. If you desire a different format, type man date in Terminal for the syntax on various formats and just change the file to output the format you want.


Comments