[SOLVED] How to execute a command when GUI is loaded?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Since Kali is based on Debian, it should use systemd. The rc-local service is executed as the very last service; try adding your script to /etc/rc.local and ensure this service is enabled.
Or create a service unit that launches the script and runs after the graphical target.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803
Rep:
Quote:
Originally Posted by berndbausch
Since Kali is based on Debian, it should use systemd. The rc-local service is executed as the very last service; try adding your script to /etc/rc.local and ensure this service is enabled.
That's what the Systemd people claim but I've found this to not be true. At least it doesn't seem to run last on OpenSUSE---it runs after "basic.target" (i.e., it's not the equivalent of the traditional "S99rclocal" SysV startup step) so I cannot fathom what the Systemd folks envisioned users would use that service for. There are some elaborate HOWTOs that I've tinkered with that try to fix this by adding a new boot target that multiuser or graphical are predecessors to. None worked for what I was looking to accomplish. IMHO, Systemd will not be done until rc-local is fixed. Desktop environments have a workaround for this (autostarting an application upon login) but plain ol' servers are left high and dry.
That's what the Systemd people claim but I've found this to not be true. At least it doesn't seem to run last on OpenSUSE---it runs after "basic.target" (i.e., it's not the equivalent of the traditional "S99rclocal" SysV startup step) so I cannot fathom what the Systemd folks envisioned users would use that service for. There are some elaborate HOWTOs that I've tinkered with that try to fix this by adding a new boot target that multiuser or graphical are predecessors to. None worked for what I was looking to accomplish. IMHO, Systemd will not be done until rc-local is fixed. Desktop environments have a workaround for this (autostarting an application upon login) but plain ol' servers are left high and dry.
I can neither confirm nor deny, but it is a moot point in this context:
Quote:
Originally Posted by ondoho
You can't do this (...) before $DISPLAY is defined, i.e. before the GUI is up.
So the "DE workaround" you mention is the correct way in this case.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803
Rep:
Quote:
Originally Posted by ondoho
I can neither confirm nor deny, but it is a moot point in this context:
So the "DE workaround" you mention is the correct way in this case.
Yes: in this case. Even if rc-local was working as it traditionally has, it might not have solved the OP's problem. Was it OK for the task to run after the GUI login was presented? Or did it need to wait for when the user completed logging in? (My guess would be the latter.)
Hmm... ~/.xsession might also solve the OP's problem and also be desktop agnostic. We tend forget about the Old Ways.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.