2

I have a macbook pro and I am in the process of binding scripts to control the backlight level on my keyboard. I wrote 2 scripts and they work perfectly I just cant get them to run on a keypress. I have xbindkeys set up and running with a configuration file named .xbindkeysrc in the configuration file I attempt to bind the scripts to my special function keys (same row as fn). I know my configuration file loads properly because when I run xbindkeys -s it shows the two attempted bindings that are not currently working. Here is the contents of my.xbindkeysrc file

###########################
# xbindkeys configuration #
###########################
#
# Version: 0.1.3
#
# If you edit this, do not forget to uncomment any lines that you change.
# The pound(#) symbol may be used anywhere for comments.
#
# A list of keys is in /usr/include/X11/keysym.h and in
# /usr/include/X11/keysymdef.h 
# The XK_ is not needed. 
#
# List of modifier (on my keyboard): 
#   Control, Shift, Mod1 (Alt), Mod2 (NumLock), 
#   Mod3 (CapsLock), Mod4, Mod5 (Scroll). 
#
# Another way to specifie a key is to use 'xev' and set the 
# keycode with c:nnn or the modifier with m:nnn where nnn is 
# the keycode or the state returned by xev 
#
# This file is created by xbindkey_config 
# The structure is : 
# # Remark 
# "command" 
# m:xxx + c:xxx 
# Shift+... 




#keystate_numlock = enable
#keystate_scrolllock = enable
#keystate_capslock = enable



"bash /opt/keyLightInc.sh"
    m:0x0 + c:238
    XF86KbdBrightnessUp 

"bash /opt/keyLightDec.sh"
    m:0x0 + c:237
    XF86KbdBrightnessDown 

#
# End of xbindkeys configuration

I started it with the verbose option. Here is the output:

screen 0 for window 259
Start program with fork+exec call
sudo: no tty present and no askpass program specified
xavier
  • 23
  • 4
  • Is there an entry in /etc/sudoers for those scripts? Why are you calling them with sudo bash? – jasonwryan Dec 21 '14 at 05:23
  • I thought I needed it because within the script a file is modified with a 0-255 value for the brightness of the keys, to modify this file it must be called by super user. I just executed the script in xterm without sudo and it worked just fine so I removed it, still no luck. Edited my original post – xavier Dec 21 '14 at 05:34
  • Do the scripts have a shebang? Can you remove the bash and just call the script? – jasonwryan Dec 21 '14 at 05:44
  • I just added #!/bin/sh to the beginning of each file, now when I call the script it says permission denied and sudo before the script path results in the error command not found – xavier Dec 21 '14 at 06:03
  • Is it executable? It doesn't sound like it. Also, is /opt/ in your PATH? – jasonwryan Dec 21 '14 at 06:07
  • Made it executable now the script is called no problem with /opt/keyLightInc.sh I edited my xbindkeys config file and relaunched xbindkeys. Still no luck. – xavier Dec 21 '14 at 06:17
  • Start it with the verbose option and see what is printed to the temrinal when you hit those keys. Mine works fine... – jasonwryan Dec 21 '14 at 06:21
  • the output is here got screen 0 for window 259; Start program with fork+exec call; sudo: no tty present and no askpass program specified – xavier Dec 21 '14 at 06:43

1 Answers1

1

If your sudoers file sets the requiretty option, then you can only call sudo from a terminal.

If your sudoers file doesn't set the requiretty option, then you can call sudo from anywhere, but if it prompts for a password, a terminal is required. The message “sudo: no tty present and no askpass program specified” indicates that sudo tried to prompt you for a password, but failed.

You can pass the -A option to tell sudo to use a different method to prompt you for a password. Since you're running in X11, you can use the ssh-askpass program distributed with OpenSSH, which prompts for a password in an X11 window.

sudo -A /usr/bin/ssh-askpass whatever-command-you-need-to-execute-as-root

Alternatively, allow yourself to run this program without entering a password.