[SOLVED] What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
wosser

[SOLVED] What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Post by wosser »

I had a problem with my mouse being too sensitive and this marvellous forum provided the answer here...
viewtopic.php?f=49&t=227410&sid=5aef897 ... 0#p1370340

The command works fine if I run it myself from a root command line.

I wanted to have this command run for all users and tried to do that by adding it to /etc/rc.local like this:

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

xinput --set-prop 'MOSART Semi. 2.4G Wireless Mouse' 'Coordinate Transformation Matrix' 1.0 0.0 0.0  0.0 1.0 0.0  0.0 0.0 3.0

exit 0
But when I rebooted, it seems that the command hasn't been executed.

rc.local has these attributes:
-rwxr-xr-x 1 root root 568 May 19 07:50 /etc/rc.local

This is a recent, fresh install of Linux Mint 18.3 Sylvia.

If this is the wrong way to do this, what should I be doing?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Mute Ant

Re: What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Post by Mute Ant »

"...the wrong way to do this..." The script rc.local runs with root privilege before Xorg has started, so your command 'xinput' doesn't arrive.

You might add the command delayed-and-detached so there's a 15 second pause before the command runs. That's not 'correct' since it simply guesses that Xorg will be running soon and that 15 seconds is long enough for that to happen.

Code: Select all

bash -c 'sleep 15 && xinput --set-prop "MOSART Semi. 2.4G Wireless Mouse" "Coordinate Transformation Matrix" 1.0 0.0 0.0  0.0 1.0 0.0  0.0 0.0 3.0' & disown
I have changed your ' to " so they all live inside the argument to bash.

I am trying out Ubuntu 18-04 MATE and the file rc.local simply isn't there any more, so I'm sure there's a better way, probably involving systemd. Good luck with that.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Post by catweazel »

Mute Ant wrote: Sat May 19, 2018 4:08 am I am trying out Ubuntu 18-04 MATE and the file rc.local simply isn't there any more, so I'm sure there's a better way, probably involving systemd. Good luck with that.
https://www.netroby.com/view/3895
Last edited by catweazel on Sat May 19, 2018 4:26 am, edited 1 time in total.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
Pjotr
Level 24
Level 24
Posts: 20133
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Post by Pjotr »

Forget rc.local; root permissions are not required for this, and rc.local is deprecated anyway.

This should work: simply create a startup application containing that command. Preferably with a "sleep" delay; the 15 seconds that Mute Ant advises are fine:

Code: Select all

sleep 15 && xinput --set-prop 'MOSART Semi. 2.4G Wireless Mouse' 'Coordinate Transformation Matrix' 1.0 0.0 0.0  0.0 1.0 0.0  0.0 0.0 3.0
Creating a startup application can be done "clickety-click" from within the graphical menu; the procedure differs slightly for each desktop environment. In Xfce you need to launch the utility Sessions and Startup.

A startup application is a user preference, so repeat this in each user account.
Last edited by Pjotr on Sat May 19, 2018 4:34 am, edited 1 time in total.
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Post by catweazel »

Mute Ant wrote: Sat May 19, 2018 4:08 am I am trying out Ubuntu 18-04 MATE and the file rc.local simply isn't there any more, so I'm sure there's a better way, probably involving systemd. Good luck with that.
Just fyi, this is the new rigmarole: https://linuxconfig.org/how-to-automati ... temd-linux
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
Pjotr
Level 24
Level 24
Posts: 20133
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Post by Pjotr »

catweazel wrote: Sat May 19, 2018 4:30 am
Mute Ant wrote: Sat May 19, 2018 4:08 am I am trying out Ubuntu 18-04 MATE and the file rc.local simply isn't there any more, so I'm sure there's a better way, probably involving systemd. Good luck with that.
Just fyi, this is the new rigmarole: https://linuxconfig.org/how-to-automati ... temd-linux
Looks interesting, but it's not relevant for the problem of the OP. See my previous message. :)
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Post by catweazel »

Pjotr wrote: Sat May 19, 2018 4:32 am ...it's not relevant for the problem of the OP.
Of course not. That's what the words 'Just fyi' were indicating. It's also why I replied to Mute Ant and not the OP.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Mute Ant

Re: What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Post by Mute Ant »

It transpires that the start of file /etc/rc.local uses #!/bin/sh and the shell sh doesn't implement disown --sigh-- so now there's three good reasons not to use the rc.local method.
o You have to change to #!/bin/bash to disown a process.
o It has to guess Xorg will be running soon.
o It's not in new Ubuntu.

I would look at the /etc/profile script. It runs for every user when a shell is started, so a command in there gets run many times. Whether it runs after Xorg has started with sufficient privilege to execute xinput I don't know.
wosser

Re: What is the "correct" way to make a simple command run when Linux Mint boots to the desktop?

Post by wosser »

Solved :)

I ended up writing a bash script in /usr/share that applies the mouse speed fix.

Then I simply call that script from each users' ~/.profile script.

Works beautifully now.

Thanks for the tips everyone.
Locked

Return to “Beginner Questions”