§ Scripting for the desktop environment

The selection of scripts here should be self-explanatory, if not leave a comment or write me an e-mail. I believe that in majority of cases you would need to tweak them to work in your particular setup. Nevertheless you should at least get an idea of how you can accomplish certain things. I run most of these scripts via keybindings in i3 or during startup.

§ xinitrc - start here

This is designed to work with Slim.

xset -b

case $1 in
xfce4)
  exec startxfce4
  ;;
*)
  xrdb -m ~/.Xresources
  setxkbmap -layout pl,us,ru -variant ,intl,phonetic -option grp:alt_space_toggle
  xset dpms 300 600 900
  xbacklight -set 80

  /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 2>&1 >/dev/null &
  eval $(gpg-agent --daemon --enable-ssh-support --disable-scdaemon)

  ~/System/hdmi1.sh

  exec dbus-launch --exit-with-session --sh-syntax i3
  ;;
esac

§ hdmi1.sh - set up external monitor

At home I use an external monitor and a wireless keyboard and mouse.

#!/bin/sh
MODE=1920x1080
amixer set Master 100% 2>&1 >/dev/null
xrandr | grep -o "HDMI1 connected" 2>&1 >/dev/null
if [ $? == 0 ]; then
  xrandr --output LVDS1 --off
  if [ "$1" != "" ]; then
    MODE=$1
  fi
  xrandr --output HDMI1 --mode $MODE --primary
else
  xrandr --output LVDS1 --primary
  amixer set Master mute 2>&1 >/dev/null
fi
feh --bg-fill `~/System/randwallpaper.sh`

§ display.sh - display switching

This is supposed to do what (usually) Fn+F7 does, that is cycle true external displays. Beware as I haven’t tested it yet in production.

#!/bin/sh
#

# check if LVDS1 is off
xrandr | awk '/LVDS1.*/,/VGA1.*/ { print $0 }' | grep -oP "\d*\.\d\*" 2>&1 >/dev/null
if [ $? == 1 ]; then
  # is off, so trun on
  xrandr --output LVDS1 --auto --primary
else
  # is on, so check others

  # check if VGA1 is connected
  xrandr | grep -oP "VGA1 connected" 2>&1 >/dev/null
  if [ $? == 0 ]; then
    # vga1 is connected, but is it on?
    xrandr | awk '/VGA1.*/,/HDMI1.*/ { print $0 }' | grep -oP "\d*\.\d\*" 2>&1 >/dev/null
    if [ $? == 0 ]; then
      # is on, so turn off
      xrandr --output VGA1 --off
    else
      # is off, so turn on
      xrandr --output VGA1 --mode 1024x768 --right-off LVDS1
    fi
  fi

  # check if HDMI1 is connected
  xrandr | grep -oP "HDMI1 connected" 2>&1 >/dev/null
  if [ $? == 0 ]; then
    # hdmi1 is connected, but is it on?
    xrandr | awk '/HDMI1.*/,/DP1.*/ { print $0 }' | grep -oP "\d*\.\d\*" 2>&1 >/dev/null
    if [ $? == 0 ]; then
      # is on, so turn off
      xrandr --output HDMI1 --off
    else
      # is off, so turn on
      xrandr --output HDMI1 --auto
    fi
  fi
fi

§ touchpad.sh - toggle touchpad

#!/bin/sh

if [ $(synclient | grep -oP "TouchpadOff\s*=\s\K(\d)") == "0" ]; then
  synclient TouchpadOff=1
  notify-send -t 1500 -u low -a touchpad.sh "Touchpad OFF"
else
  synclient TouchpadOff=0
  notify-send -t 1500 -u low -a touchpad.sh "Touchpad ON"
fi

§ joy.sh - turn-off joystick-as-a-mouse

I don’t really know why I still have in my X config to treat a joystick as a pointer device… I guess for emergencies.

#!/bin/sh

JOYID=`xinput | grep -P "(Joy|Analog)" | head -n1 | grep -oP "id=\K\d+"`
if [ $? == 0 ]; then
  JOYMOUSE=`xinput --list-props $JOYID | grep -oP "Generate Mouse Events \(\K\d+"`
  JOYKEY=`xinput --list-props $JOYID |  grep -oP "Generate Key Events \(\K\d+"`
  xinput --set-int-prop $JOYID $JOYMOUSE 8 0
  xinput --set-int-prop $JOYID $JOYKEY 8 0
fi

§ spineject.sh - spindown an external drive

This is meant to be used with external hard drives, on USB sticks a simple eject will do the job.

#!/bin/sh
if [ "$1" == "" ]; then
  echo "DRIVE: /dev/sdb"
  DRIVE=/dev/sdb
else
  echo "DRIVE: $1"
  DRIVE=$1
fi
sudo sdparm --readonly --command=stop $DRIVE
echo DONE

§ jackd.sh - start JackD

In case you happen to be doing audio on Linux.

#!/bin/sh

# load pulseaudio modules
pactl load-module module-jack-sink
pactl load-module module-jack-source
# start qjackd
qjackctl &
comments powered by Disqus
Last update: 2013-01-28. » LINK » TXT » ATOM. Go to the top. Licence CC-BY-NC-SA.
If you find this interesting go ahead and leave a comment or add a star.
Any and all feedback is appreciated!