View previous topic :: View next topic |
Author |
Message |
returnof Snekiepete n00b
Joined: 22 Dec 2016 Posts: 36
|
Posted: Tue Nov 19, 2019 5:08 pm Post subject: Autostart program if device exists |
|
|
I am trying to figure out how to write a startup script that will run an application at autostart if a specific device is connected.
In this case, I am talking about Polychromatic for my Razer usb peripherals. I only want Polychromatic-tray to run if the peripherals are connected and to not run when the laptop is not docked with them plugged in.
Is this possible? |
|
Back to top |
|
|
mike155 Advocate
Joined: 17 Sep 2010 Posts: 4438 Location: Frankfurt, Germany
|
Posted: Tue Nov 19, 2019 8:36 pm Post subject: |
|
|
What exactly do you mean with a 'startup script ... at autostart'?
Do you want a script that will be started when you boot you computer? Or when you start your desktop environment? Or do you want a script that will be started automatically whenever you plugin in your Razer usb peripherals (from udev)?
If the former is the case, you could write a shell script that tests whether your Razer usb peripherals are available. That script could grep the output of 'lsub' and start your program if it finds a certain string (the USB name of our Razor peripherals). Something like:
Code: | if /usr/bin/lsusb | grep "046d:c05a"
then
start_polychromatic-tray
fi |
(I used "046d:c05a" because that's my Logitech mouse. You should use another string, of course. Look at the output of 'lsub' when your Razer usb peripherals are plugged in and compare it to the output of 'lsub' when your Razer usb peripherals are NOT plugged in. If you can't find such a string in the output of 'lsusb', try 'lsusb -v'.)
Alternative: if udev creates special device files in /dev whenever you plug in your Razor USB peripherals, your start script could look for one of those device files:
Code: | if test -e /dev/<device-name>
then
start_polychromatic-tray
fi |
|
|
Back to top |
|
|
returnof Snekiepete n00b
Joined: 22 Dec 2016 Posts: 36
|
Posted: Tue Nov 19, 2019 9:52 pm Post subject: |
|
|
I think what you are proposing will work in either case. I will test it out and follow-up. I appreciate the advice. |
|
Back to top |
|
|
|