How to run a Bash script when using a graphical desktop login

2

I am running the MATE desktop on Arch Linux, and I have a bash script that I run which:

  • Configures MATE to work with multiple monitors
  • Connects the PC to the internet
  • Changes my mouse speed

I have to manually execute this script every time I login graphically. How can I do this automatically? I have tried the following:

  • Putting the script in a ~/.profile file. Nothing happened.
  • Putting the script in a ~/.initrc file. Nothing happened.
  • Putting the script in a ~/.xsession file. Nothing happened.
  • systemd won't work because, as far as I can tell, it tries to execute the script functions too early. It must be executed only once the user has logged in, not during startup.

Edit: The script require root privledges aswell!

Spenser Truex

Posted 2016-07-16T23:32:56.773

Reputation: 131

I don't run mate - but something similar to KDE's autostart module might be handy. http://superuser.com/a/809799/10165 is an example of me doing a xrandr script with autostart. Mate might call it startup applications. I don't have a mate desktop to test it on and to post a full answer, so if anyone does, and wants to post an answer with this I'm cool.

– Journeyman Geek – 2016-07-17T04:08:13.457

@JourneymanGeek Funny enough my script also does the same xrandr commands that you laid out in your question. – Spenser Truex – 2016-07-17T17:18:41.810

@JourneymanGeek After using the MATE autostart application I am sorry to report that I must manually put in the root password when I startup. – Spenser Truex – 2016-07-19T05:01:55.873

you can give sudo permissions for a single command too. That might be a better idea. And since it works, post it as an answer – Journeyman Geek – 2016-07-20T00:28:32.367

Answers

1

Thanks to a comment by @JorneymanGeek I have been able to use the MATE autostart application to do what I need. I resolved to issues that come with needing to put in a password by using NOPASSWD in visudo, which allows me to call sudo COMMAND at the command line wihtout using a password.

This is generally a bad idea, but it works.

Spenser Truex

Posted 2016-07-16T23:32:56.773

Reputation: 131

0

You can sometimes (not always) use ~/.xsession to achieve what you want. This is usually very system dependent and you may have to dig through your system's startup script. Please see this Unix & Linux Stack Exchange question for more details

Satya Mishra

Posted 2016-07-16T23:32:56.773

Reputation: 121

Unfortunately ~/.session doesn't work in my case. – Spenser Truex – 2016-07-17T17:29:11.167

@SpenserTruex Yeah, it doesn't work always. Just to confirm, the filename is ~/.xsession NOT ~/.session. – Satya Mishra – 2016-07-17T17:54:57.620

it is ~/.xsession. – Spenser Truex – 2016-07-17T18:54:17.530

@SpenserTruex OK. I'm not an Arch user. After some more digging around ~/.xprofile seems to be the session start file used by most modern display managers.

– Satya Mishra – 2016-07-18T21:11:43.997

0

You could either put it in:

  • ~/.bashrc (will run after all apps initialized)
  • /etc/rc.local (will run AS ROOT after all services are running, but before you logon with your username)

Matt

Posted 2016-07-16T23:32:56.773

Reputation: 113

Is there a way to run ~/.bashrc as root to get both the benefits or running after apps have initialized and as root? – Spenser Truex – 2016-07-18T23:05:53.233

Also I tried using rc.local and it produces no results. – Spenser Truex – 2016-07-19T00:38:00.780