Ubuntu – Timestamp in Exec= line of .desktop file possible

bashdesktop

Lubuntu 16.04 – Openbox session

I can use the terminal to open a time-stamped file with gedit:

gedit ~/$(date +%Y%m%d%H%M%S).txt

The command can also be used via a keyboard shortcut in Openbox.

<keybind key="W-4">        # gedit time-stamped file
  <action name="Execute"><command>sh -c 'gedit ~/$(date +%Y%m%d%H%M%S).txt'</command></action>
</keybind>

But I can't do the same via the Exec= line of a .desktop file.

Exec=sh -c 'gedit ~/$(date +%Y%m%d%H%M%S).txt'

just creates a file called ~/.txt

So how do I get a .desktop file to do what I want?

Best Answer

Unfortunately, .desktop files don't always call sub-shell $() commands the way we would like them to. One way to do this that I have found would be to create another script that contains the sub-shell command to open the file like that.

The Exec line would look like:

Exec=/path/to/script

then your script file would contain the command to open your new file:

#!/bin/sh

gedit ~/$(date +%Y%m%d%H%M%S).txt

the script would also have to be executable:

chmod +x /path/to/script

Hope this helps!

Related Question