Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Autostart program if device exists
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
returnof Snekiepete
n00b
n00b


Joined: 22 Dec 2016
Posts: 36

PostPosted: Tue Nov 19, 2019 5:08 pm    Post subject: Autostart program if device exists Reply with quote

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
View user's profile Send private message
mike155
Veteran
Veteran


Joined: 17 Sep 2010
Posts: 1994
Location: Frankfurt, Germany

PostPosted: Tue Nov 19, 2019 8:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
returnof Snekiepete
n00b
n00b


Joined: 22 Dec 2016
Posts: 36

PostPosted: Tue Nov 19, 2019 9:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum