Thursday, April 18, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 924  / 2 Years ago, fri, july 1, 2022, 5:05:29

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.


More From » bash

 Answers
4

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.


[#23616] Saturday, July 2, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
olltea

Total Points: 238
Total Questions: 115
Total Answers: 107

Location: Moldova
Member since Tue, Feb 7, 2023
1 Year ago
;