Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Writing a script and running into permissions issues.

  1. #1
    Join Date
    Mar 2007
    Location
    TN, US
    Beans
    607
    Distro
    Ubuntu

    Writing a script and running into permissions issues.

    So I recently wrote a script that toggles my laptop's touchpad on or off using xinput, and it works beautifully when run from terminal. I was attempting to set this script to auto-run whenever my mouse is plugged in, but it seems to be running the script (echo statements I put in the script for debugging are working) without actually disabling the touchpad. I am using halevt to detect the device and launch the command, so I assume I am doing something wrong with halevt and permissions. Any ideas?

    The Script:
    Code:
    # toggleTouchpad by Brendon Dugan
    # Toggles a touchpad on or off depending on it's current state or CLI argument
    #
    # To configure, run the command 'xinput list' in terminal and identify your touch pad.
    # Using the output of the above command, change the touchpadString variable to a substring
    # of your touchpad's description that is unique to that device.
    #
    # To run, simply type 'toggleTouchpad' to toggle your touchpad on or off, or
    # 'toggleTouchpad on' to explicitly turn your touchpad on, or
    # 'toggleTouchpad off' to explicitly turn it off.
    #
    # Enjoy!
    touchpadString="TouchPad"
    touchpadID=$(xinput list | grep $touchpadString | awk -F " " '{print $6}' | awk -F "=" '{print $2}')
    touchpadEnabled=$(xinput list-props $touchpadID | grep "Device Enabled" | awk -F ":" '{print $2}')
    
    # Check for arguments on the command line
    if test $# -eq 1
    then
    	# Change the argument to lowercase
    	arg1=$(echo $1 | tr [:upper:] [:lower:])
    	cliArg=1
    else
    	# There is no argument.
    	cliArg=0
    fi
    
    if [ $cliArg -eq 1 ]
    then
    	# If there's an argument, check to see whether it is on, off, or junk
    	if [ $arg1 = 'on' ]
    	then
    		# The argument was 'on', so turn the touchpad on 
    		xinput --set-prop $touchpadID "Device Enabled" 1
    		echo "ON"
    	elif [ $arg1 = 'off' ]
    	then
    		# The argument was 'off', so turn the touchpad off 
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		echo "OFF"
    	else
    		# The argument was junk, so do nothing 
    		sleep 1
    	fi
    else
    	# There was no argument, so just toggle the touchpad to the opposite
    	# of the state it has now.
    	if [ $touchpadEnabled -eq 1 ]
    	then
    		xinput --set-prop $touchpadID "Device Enabled" 0
    	else
    		xinput --set-prop $touchpadID "Device Enabled" 1
    	fi
    fi
    The command to launch halevt:
    Code:
    sudo halevt -u brendon -g brendon -c /home/brendon/.halevt.xml
    The halevt config file:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <halevt:Configuration version="0.1" xmlns:halevt="http://www.environnement.ens.fr/perso/dumas/halevt.html">
    	<halevt:Device match="hal.info.udi = /org/freedesktop/Hal/devices/usb_device_46d_c70e_00076142E023">
    		<halevt:Insertion exec="/home/brendon/bin/toggleTouchpad off"/>
    		<halevt:Removal exec="/home/brendon/bin/toggleTouchpad on"/>
    	</halevt:Device>
    </halevt:Configuration>
    Registered Linux user 446122 , Registered Machine 352936.

  2. #2
    Join Date
    Nov 2009
    Location
    The Netherlands
    Beans
    239
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Writing a script and running into permissions issues.

    I have my own script, which switches the touchpad on when it's off and off when it's on. with the touchpad device name hardcoded in the script. I used System>Preferences>Keyboard Shortcuts to run the script whenever i press the windows key and F2.
    That's not really what you're trying to do, but it works for me and it might work for you as well

  3. #3
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Writing a script and running into permissions issues.

    Some things I'd check.

    1. In the environment where there script runs automatically and doesn't work, is the DISPLAY environment variable set?
    2. Under which user account does it run?
    3. Does stderr go anywhere?

  4. #4
    Join Date
    Mar 2007
    Location
    TN, US
    Beans
    607
    Distro
    Ubuntu

    Re: Writing a script and running into permissions issues.

    Quote Originally Posted by ziekfiguur View Post
    I have my own script, which switches the touchpad on when it's off and off when it's on. with the touchpad device name hardcoded in the script. I used System>Preferences>Keyboard Shortcuts to run the script whenever i press the windows key and F2.
    That's not really what you're trying to do, but it works for me and it might work for you as well
    I actually have mine set to a keyboard shortcut as well, but would like to automate it even more.
    Registered Linux user 446122 , Registered Machine 352936.

  5. #5
    Join Date
    Mar 2007
    Location
    TN, US
    Beans
    607
    Distro
    Ubuntu

    Re: Writing a script and running into permissions issues.

    Quote Originally Posted by spjackson View Post
    Some things I'd check.

    1. In the environment where there script runs automatically and doesn't work, is the DISPLAY environment variable set?
    2. Under which user account does it run?
    3. Does stderr go anywhere?
    Those are great questions... unfortunately I have no idea. Any suggestions on how to find out the answers?
    Registered Linux user 446122 , Registered Machine 352936.

  6. #6
    Join Date
    Nov 2009
    Location
    The Netherlands
    Beans
    239
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Writing a script and running into permissions issues.

    1:
    Code:
    if [ -n "$DISPLAY ]
    then
        #Display is set
    fi
    2:
    Code:
    echo "$USER" > /tmp/somefile
    and check the contents of somefile after the script has been run.

    don't know about 3 though, sorry.

  7. #7
    Join Date
    May 2006
    Beans
    1,790

    Re: Writing a script and running into permissions issues.

    I don't know if this helps, but I added a line to report the new setting after disabling the touchpad:

    Code:
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    and it reports 1 when run from halevt, even though we set it to 0 on the line before.

  8. #8
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Writing a script and running into permissions issues.

    Quote Originally Posted by ziekfiguur View Post
    1:
    Code:
    if [ -n "$DISPLAY ]
    then
        #Display is set
    fi
    2:
    Code:
    echo "$USER" > /tmp/somefile
    and check the contents of somefile after the script has been run.

    don't know about 3 though, sorry.
    Agreed. brennydoogles, you said that you had put echo statements in to show that it was being called, so I'd just do:
    Code:
    echo "DISPLAY is $DISPLAY" >> /tmp/somefile
    id >> /tmp/somefile
    I don't know where stderr is going to. I'd need to investigate the documentation for halevt, but I would also put something in to force an error and see if I can find where it goes. e.g.
    Code:
    ls no/such/file

  9. #9
    Join Date
    May 2006
    Beans
    1,790

    Re: Writing a script and running into permissions issues.

    Quote Originally Posted by Arndt View Post
    I don't know if this helps, but I added a line to report the new setting after disabling the touchpad:

    Code:
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    and it reports 1 when run from halevt, even though we set it to 0 on the line before.
    I think something else is enabling the touchpad. If I do this:

    Code:
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		sleep 5
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		sleep 5
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    the output (captured in a file) is this:

    Device Enabled (125): 0
    Device Enabled (125): 0
    Device Enabled (125): 1
    Device Enabled (125): 1
    Device Enabled (125): 0
    Device Enabled (125): 0
    Device Enabled (125): 0
    Device Enabled (125): 0
    Device Enabled (125): 0

  10. #10
    Join Date
    Mar 2007
    Location
    TN, US
    Beans
    607
    Distro
    Ubuntu

    Re: Writing a script and running into permissions issues.

    Quote Originally Posted by Arndt View Post
    I think something else is enabling the touchpad. If I do this:

    Code:
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		sleep 5
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		sleep 5
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    		xinput --set-prop $touchpadID "Device Enabled" 0
    		xinput list-props $touchpadID| grep "Enabled"
    the output (captured in a file) is this:

    Device Enabled (125): 0
    Device Enabled (125): 0
    Device Enabled (125): 1
    Device Enabled (125): 1
    Device Enabled (125): 0
    Device Enabled (125): 0
    Device Enabled (125): 0
    Device Enabled (125): 0
    Device Enabled (125): 0

    On my machine this results in the following output:
    Code:
    Device Enabled (125):	0
    Device Enabled (125):	0
    Device Enabled (125):	0
    Device Enabled (125):	0
    Device Enabled (125):	0
    Device Enabled (125):	0
    Device Enabled (125):	0
    Device Enabled (125):	0
    Device Enabled (125):	0
    Which also successfully disabled the touchpad. If you have Ubuntu set to automatically disable your touchpad while you type, it could be creating the output you received by re-enabling the touchpad after the specified period of time from when you typed the command. I have that feature disabled, so it appears to be a possible candidate.
    Registered Linux user 446122 , Registered Machine 352936.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •