Score:1

How to invoke a command when starting a user session?

za flag

OS: Ubuntu 22.10
graphic card: nvidia
monitor: philips

Issue: how to change default gamma after X11 startup.

The gamma command I wish to invoke is either:

xgamma -rgamma 0.6 -ggamma 0.5 -bgamma 0.5

or

xrandr --output DP-0 --gamma 0.6:0.5:0.5

I want to set the gamma to default per above, when my user session starts.

I have attempted:

  1. To invoke a .sh file at startup by adding an entry to the "Startup Applications". This is unsuccessful: the .sh will not invoke. Adding a 10 second delay does nothing.
  2. Editing the file, xinitrc, to add the xgamma or xrandr commands. Also unsuccessful.
  3. Creating a .conf file in user/share/X11/xorg.conf.d Also unsuccessful. This caused my pc not to boot, requiring a recovery session as root, to remove the .conf file.
  4. Creating an .sh file on desktop, and invoking after user session starts. Successful, partly. But this is not default, and the system will over-ride the .sh command upon sleep and invoking other applications. Not the solution I am hoping to achieve.

Any help is sincerely appreciated. Thank you.

Update #1:

As suggested in the comments, I ran this command as a startup application:

sh -c '{ echo "started"; xgamma -rgamma 0.6 -ggamma 0.5 -bgamma 0.5; echo "$?"; echo "ended"; } > /home/user/startupapp.log 2>&1'

Here are the contents of the logs from cat ~/startupapp.log... for the xgamma command:

started
-> Red 1.000, Green 1.000, Blue 1.000 
<- Red 0.600, Green 0.500, Blue 0.500 
0 
ended

And for the xrandr command:

started
0
ended

After invoking the xgamma command, though the log shows the change in gamma, the monitor remains at gamma values 1.00.

sudodus avatar
jp flag
I think you should create a desktop file, and in that file let the Exec line point to your shellscript. Put that file into the 'autostart' directory and logout+login or reboot. The following links might help you: [Autostart system where part runs with elevated permissons](https://askubuntu.com/questions/1353879/lubuntu-20-04-run-a-script-at-login-which-executes-in-a-terminal-window/1354182#1354182) and [Rotating the desktop](https://askubuntu.com/questions/1251814/xrandr-command-in-startup-script-has-no-effect-but-script-does-run-and-command/1251882#1251882).
Raffa avatar
jp flag
A startup application runs after X is started and a user session is also started ... So if your script runs in your DE environment, it should run in a startup application as well ... Please paste this in the command field of a new startup application `sh -c '{ echo "started"; xgamma -rgamma 0.6 -ggamma 0.5 -bgamma 0.5; echo "$?"; echo "ended"; } > /home/user/startupapp.log 2>&1'` after changing `user` to your username then logout and back in and show us the output of `cat ~/startupapp.log` ... Do the same for the `xrandr` command as well.
za flag
@Raffa. Many thanks for reply. Excuse my delay.
za flag
@Raffa. Here are the contents of the logs... for the xgamma command.. started -> Red 1.000, Green 1.000, Blue 1.000 <- Red 0.600, Green 0.500, Blue 0.500 0 ended for the xrandr command... started 0 ended .... after invoking the xgamma command, though the log shows the change in gamma, the monitor remains at gamma values 1.00
za flag
@ Raffa.. as you see, I am unable to format my reply. any tips?
Raffa avatar
jp flag
It appears both commands are successfully run ... I suggest you start investigating the monitor side ... e.g. builtin color profile or settings ... Probably adding a delay before the command e.g. `sh -c 'sleep 20; echo ...'` might help.
za flag
@ Raffa. thanks for reply. Agree. Something in my system is over-riding the xgamma command. The trouble is, I don't know what. Might you know... Has Linux some means to log everything at boot to startup to the moment the desktop screen appears? If so, where could I find this?
Raffa avatar
jp flag
You could try searching the systemd journal e.g. `journalctl | grep -i "xgamma"` and `journalctl -b` for boot logs.
za flag
@ Raffa. Many thanks again for your reply. Very helpful as a tutorial. I discovered the logs are messy, and the issue seems to be with Nvidia (as far as I can tell currently). At startup, I removed the xgamma script, and replaced it with a command to invoke the Nvidia-settings (after editing the settings) with a 3 second delay. This works on startup, but when the system awakes from a sleep, the system defaults back to the gamma 1.0 values. I don't know if this is a bug with Nvidia or my system. When I had the idea to alter gamma, I had no inklings this would be so complicated to accomplish.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.