Well I found out that part of the problem is that the pacmd commands have to run as the user that is logged in. They don't work as root so now my udev rule is:
Code:
SYSFS{idVendor}=="046d", SYSFS{idProduct}=="0a0b", MODE="660", RUN+="/usr/bin/callheadset"
callheadset is:
Code:
#!/bin/bash
echo "running headset" >> /home/luke-jennings/Desktop/headset
sudo chmod +w /home/luke-jennings/Desktop/headset
su luke-jennings -c /usr/local/bin/headset
and /usr/local/bin/headset is:
Code:
#!/bin/bash
echo "turning up alsamixer" >> /home/luke-jennings/Desktop/headset
amixer -c 1 sset Speaker,0 80%
echo "setting mic" >> /home/luke-jennings/Desktop/headset
pacmd set-default-source $(pacmd list-sources | grep "alsa_input.usb-Logitech_Logitech_USB_Headset-00-Headset.analog-mono" -B1 | grep index | awk '{ print $2;}')
echo "setting earphones" >> /home/luke-jennings/Desktop/headset
pacmd set-default-sink $(pacmd list-sinks | grep "alsa_output.usb-Logitech_Logitech_USB_Headset-00-Headset.analog-stereo" -B1 | grep index | awk '{ print $2; }')
But the echo file still reads rather randomly and the scripts don't do what they were meant to. the echo file is:
Code:
running headset
turning up alsamixer
setting mic
setting earphones
running headset
running headset
running headset
running headset
running headset
running headset
running headset
running headset
turning up alsamixer
setting mic
setting earphones
turning up alsamixer
setting mic
turning up alsamixer
turning up alsamixer
turning up alsamixer
turning up alsamixer
turning up alsamixer
turning up alsamixer
setting mic
setting mic
setting mic
setting mic
setting mic
setting mic
setting earphones
setting earphones
setting earphones
setting earphones
setting earphones
setting earphones
setting earphones
but as a root user running gives the expected
Code:
running headset
turning up alsamixer
setting mic
setting earphones
in the echo file.
Any one have any idea why the udev rule is doing this I am very stuck on this part. Any suggestions welcome.
Bookmarks