Timestamp in Exec= line of .desktop file possible?

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:


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


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!

The issue

A script is not necessary.

The issue is not that a .desktop file cannot run commands with subshells, since

Exec=/bin/bash -c "echo $(date) > ~/out.txt"

works perfectly fine in a .desktop file.

Fiddling around with the command, I came to the conclusion that the % -character is causing the issue. I have no explanation for it though, and so far I could not find information on how to solve or escape that.

I therefore went looking for a command to get the time without using the suspected character.

Alternatively use Ruby for the date & time

This lead me to Ruby, which produces the current date & time from the command:

$ ruby -e 'puts Time.now.inspect'
2016-05-29 16:12:36 +0200

When we edit the output a bit with awk, removing spaces and delimiters, we have just what we want, and a working command in the .desktop file, since we don't use %:

Exec=/bin/bash -c  "gedit ~/$(ruby -e 'puts Time.now.inspect' | awk -F'[: -]' '{print $1$2$3$4$5$6}')"

enter image description here


No doubt, the command can be "charmed up" a bit, I will probably edit the answer a bit today or tomorrow.