3

I am trying to create a macro to print a timestamp, similar to Google Sheets Ctrl+Shift+; shortcu or in Windows Notepad (I think it was F5), and I am using Settings → KeyboardKeyboard ShortcutsCustom Shortcuts. I have entered:

  • Name: Timestamp
  • Command: date +"%a, %B %d, %Y"
  • Shortcut: Super+Backslash

However I cannot get it to enter the timestamp in the terminal, Google Keep, or Gedit.

Specs:

Host: Laptop AB  
BIOS: INSYDE Corp. 3.17 (10/27/2022)  
OS: Ubuntu bookworm/sid (jammy) x86_64  
DE: GNOME 42.9 (wayland)  
Kernel: Linux 6.2.0-39-generic  
Shell: bash 5.1.16  
WM: Mutter  
CPU: 11th Gen Intel i7-1165G7 (8) @ 4.7GHz   
GPU: Intel TigerLake-LP GT2 [Iris Xe Graphics]  
GPU Driver: i915  
Memory: 6.81 GiB / 15.39 GiB (44%)    
Disk (/): 16G / 228G (8%)  
Network: Wifi6  
Bluetooth: Intel Corp. AX210
QRP
  • 96

1 Answers1

3

You can achieve this using a script file and xdotool.

  1. Install xdotool using this command:

    sudo apt install xdotool
    
  2. Create a script named timestamp.sh and add the following lines:

    #!/bin/bash
    

    Get the current timestamp

    timestamp=$(date +"%a, %B %d, %Y")

    Use xdotool to simulate typing the timestamp

    sleep 1 xdotool type --clearmodifiers "$timestamp"

  3. Now give the file the necessary permissions using this command:

    chmod +x timestamp.sh
    
  4. Configure the shortcut by going to SettingsKeyboardKeyboard ShortcutsCustom Shortcuts. Give the desired name for the shortcut in the Name field. In the Command field, use the command /path/to/the/file/timestamp.sh. Also, add the shortcut that you want to use (I used Ctrl+Backslash).

    custom-shortcuts

That's it. Now you can use this shortcut to print the timestamp anywhere.

Ajay
  • 1,246
  • I have set it up as you described, but there is no output. I tried running in terminal each command from the script but got no output, perhaps the shebang cannot be run directly in the terminal. I have also tried giving the path as literal and logical:: /home/qrp/timestamp.sh and ~/timestamp.sh, neither path made any difference, still no output – QRP Jan 03 '24 at 19:56
  • Listed in Nemo: -rwxrwxr-x 1 qrp qrp 177 Jan 3 12:57 timestamp.sh* – QRP Jan 03 '24 at 20:02
  • @QRP I just noticed from your "Specs" that you are using Wayland not X - you can try modifying the solution to use an Equivalent to xdotool for Wayland – steeldriver Jan 04 '24 at 14:51