2

This is a followup to a question about dialog boxes.

I want to show a dialog box both at the start of a session, and after n minutes of inactivity. I have decided to use zenity and xautolock. I have success invoking both from the command line (bash).

zenity --text=text --warning
xautolock -time 15 -locker "zenity --text=sometext --warning"

However, there are some constraints:

  • The text has multiple words. If it has spaces, zenity will only show the first word and try to parse the other words as parameters. To fix this, I enclose the text in double quotes ("), but it leads to:
  • xautolock takes the entire zenity command as an option for its -locker parameter. The command has multiple words, so I have to enclose it in quotes. But it already had quotes originally, so it conflicts on quotes-inside-quotes.
  • I want the alert text to be customizable, so I'm using --text="$(cat .filename)".

So now what I have is:

zenity --text="$(cat .filename)" --warning
xautolock -time 15 -locker "zenity --text=\"$(cat .filename)\" --warning"

If I run each line separately on a terminal session (bash), they do work. The cursor gets stalled waiting for the process to terminate, but the dialog boxes are displayed the way I need them.

Now I need it to start automatically with no user intervention. What I did:

  • I've put each line separetedly on the Startup Applications list. Instead of showing the desired text, they will show $(cat on the dialog box.
  • I created a command.sh file on my ~ folder, pasted these two lines, made it executable.
  • Running the script from the command line works.
  • Puting ~/command.sh as an entry on Startup Applications does not work. Nothing happens, nothing is displayed, no error message, nothing. According to this answer, it should work.
  • Putting /home/username/command.sh does work, but this user is just a "skel" that gets copied to a guest user folder created upon login, so the username folder will be "guest-RANDOMSTRING", and I can't set is as a Startup Applications entry. For permission reasons, I can't set in to the "skel" user as well.
2

Try putting them in a script and adding that script as the entry in your Startup Applications. It's hard enough to use environment variables and ~ in desktop files, let alone full-fledged command substitution, as evinced by Desktop Files don't seem to use $PATH correctly and How to include environment Variable in launcher for icon.

  • Thanks, your comment and the first link have led me in the right direction! – That Brazilian Guy Aug 16 '14 at 17:28
2

Turns out each entry on the Startup Applications list gets created as a .desktop file on ~/.config/autostart$.

As mentioned by both @muru's answer and an answer on the question he linked, .desktop files don't expand the tilde as the shell would. Neither they seem to have the ${HOME} variable.

So the solution was to add the following line to the ~/.pam_environment file:

PATH DEFAULT=${PATH}:${HOME}/scripts

Then place my .sh script on the ~/scripts folder, and add script.sh, no prefixes, to the Startup Applications list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.