Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-09-16 09:48:07

dmvmak
Member
Registered: 2021-09-16
Posts: 1

Xfce Launcher Command Escapes

I wanted to add a Launcher or shortcut to my Xfce Panel which would copy the current date to my clipboard.

I'm using Xfce 4.16 on Manjaro 21.1 which is Arch-based.

I know that, in a terminal, date will print the current date and time. Further, it is possible to format the date using the +"" option with format sequences. For example:

date +"%A, %B %-d, %Y %-I:%M:%S %p"
Thursday, September 16, 2021 2:39:36 AM

xclip allows me to send text to the clipboard.

And by combining date and xclip it is possible to send the current date to the clipboard. The following does what I want when entered at a terminal.

date +"%A, %B %-d, %Y %-I:%M:%S %p" | xclip -selection clipboard -r

I'm using Bash in my terminal. And Bash has an option (-c) to accept a string as a command. Also, if we're going to send a string as input to Bash then it might be important to escape that string. The Bash manual page has a section on QUOTING which says we can use single quotes to escape a string.

When you configure a new Launcher in Xfce, you are asked to provide a Command. I thought a good first attempt would be my Bash command inside a single-quoted string.

bash -c 'date +"%A, %B %-d, %Y %-I:%M:%S %p" | xclip -selection clipboard -r'

However, when I placed this string in the Command field of a Xfce Launcher and ran it, my clipboard was filled with garbage.

,  d,  I::

This has elements of the string I passed to date: like the commas and colons. But the percent sign sequences are missing.

I thought there might be additional escape sequences associated with the Xfce Launcher. Eventually, I found the Desktop Entry Specification on which the Launcher is based. Under the section on the Exec key, it is explained there are field codes which are expanded by the program launcher. Field codes are specified with percent sign %f  And they can be escaped by doubling the percent sign %%f  This seemed like the reason why my Command string was not working. So, I carefully doubled the percent signs from my first attempt.

bash -c 'date +"%%A, %%B %%-d, %%Y %%-I:%%M:%%S %%p" | xclip -selection clipboard -r'

When I ran this Command, a properly formatted date was sent to my clipboard.

Thursday, September 16, 2021 4:21:21 AM

The underlying issue with my Launcher Command was that I had to escape both for Bash and for field codes which come from the Exec key of the Desktop Entry Specification.

References

Offline

Board footer

Powered by FluxBB