Friday, March 02, 2012

5.1 amd64 K43U: ksh script for Asus K43U keyboard shortcut in spectrwm.

Hi,

I've written a simple script to use my K43U keyboard shortcuts. As stated previously, Fn+F1 (sleep) and Fn+F7 (Off LCD) shortcuts is working. But as the Fn button is undetected in OpenBSD or xorg, I cannot use the Fn button to create other shorcuts, instead I need rely on spectrwm's MOD key. I might change this back to Fn key if later on it's workable.

What's the purpose of this (current) script?
- MOD+F10 to mute/unmute master volume (mixerctl outputs.master.mute)
- MOD+F11 to decrease master volume (mixerctl outputs.master. For both LR channel)
- MOF+F12 to increase master volume (mixerctl outputs.master. For both LR channel)

If you're using xstatbar, like me, xstatbar will show a graph of master volume for each Left/Right channel. So by using this script, you can see how much percentage of the volume you increase/decrease.

Why ksh? Because OpenBSD's default SHELL is ksh and I'm using it. This script might work with other shell.

Copy the asusfn.sh to either your $HOME or if you want to use it exclusively for spectrwm (scrotwm), copy it to /usr/local/share/scrotwm/ but make sure to alter my .scrotwm.conf below accordingly as I put my asusfn.sh in $HOME. Make sure to chmod the asusfn.sh to executable.

Manual usage is:
$ ./asusfn.sh [param]

Replace [param] with:
aup : To increase volume.
adn : To decrease volume.
amt : To mute/unmute volume.

This top part is snippet of my $HOME/.scrotwm.conf. As stated above, alter accordingly.

# This is for asusfn.sh
program[asusaup] = /home/karl/asusfn.sh aup
program[asusadn] = /home/karl/asusfn.sh adn
program[asusamt] = /home/karl/asusfn.sh amt
# This is for asusfn.sh
bind[asusaup] = MOD+F12
bind[asusadn] = MOD+F11
bind[asusamt] = MOD+F10
view raw .scrotwm.conf hosted with ❤ by GitHub
#!/bin/ksh
# asusfn.sh - v1.0 Ahmad Zulkarnain 2012
# This script is to manipulate Fn+Fx keys on my Asus K43U laptop.
# Made for spectrwm but might work with other tiling wm.
### Usage ###
# ./asusfn.sh [parameter]
#
# Accepted parameters are:
# aup = This is to turn up master volume (mixerctl outputs.master) until max (set to 255. Changable)
# adn = Turn down master vol (mixerctl outputs.master) until min (set to 0. Changable)
# amt = This is to mute/unmute master vol (mixerctl outputs.master.mute)
### This is Mixer Variables ###
# Let's get the current outputs.master value for both output channels.
l=$(mixerctl outputs.master | sed s/.*=// | sed s/\,.*//)
r=$(mixerctl outputs.master | sed s/.*,//)
# This is the mute value of outputs.master.mute.
m=$(mixerctl outputs.master.mute | sed s/.*=//)
# Set Min/Max volume
min=0
max=255
# Set the increment value
i=5
# Get increased value for both output channels. If more than $max, set to $max.
# This if for the left channel.
li=$( if (( $((l+i)) <= $max ))
then
print $((l+i))
else
print $max
fi )
# This is for the right channel.
ri=$( if (( $((r+i)) <= $max ))
then
print $((r+i))
else
print $max
fi )
# Get decreased value for both output channels. If less than $min, set to $min.
# This is for the left channel.
ld=$( if (( $((l-i)) >= $min ))
then
print $((l-i))
else
print $min
fi )
# This is for the right channel.
rd=$( if (( $((r-i)) >= $min ))
then
print $((r-i))
else
print $min
fi )
### Time for action ###
# Increase / Decrease volume for both left/right channel.
if [[ $1 = "aup" ]]
then
mixerctl outputs.master=$li,$ri
elif [[ $1 = "adn" ]]
then
mixerctl outputs.master=$ld,$rd
# Mute/Unmute the master outputs.
elif [[ $1 = "amt" ]]
then
if [[ $m = "off" ]]
then
mixerctl outputs.master.mute=on
else
mixerctl outputs.master.mute=off
fi
elif [[ $1 = "info" ]]
then
echo "Info: l = $l, r = $r, li = $li, ri = $ri, ld = $ld, rd = $rd"
else
echo "Usage $0 [aup|adn|amt]"
fi
view raw asusfn.sh hosted with ❤ by GitHub


And this part above is the asusfn.sh. If you read the script carefully, you can see that you can also use the command:

$ ./asusfn.sh info

Which is basically my debugging for the script. I'm not an expert on ksh scripting so I used that to check values/env/bla bla etc.

Future (might be) improvements:
- MOD+F2 to enable/disable athn0 (Wireless LAN)
- MOD+F8 to change display output
- MOD+F9 to enable/disable touchpad

I also found that there's acpiasus which is the Hotkeys driver for Asus's laptop. Currently not automatically working with this machine-o-mine so I need to search for clues on it.

Legal stuff. You can freely copy/use/alter the script any way you want. Don't mock my programming skill because I'm not a programmer and I know this script can be made more simpler. If you alter the script and gave it somebody, make sure you tell them it's not my version. If you find this script useful, thank me or don't either way it's ok. Later.

1 comment:

Benjamin Francom said...

Thanks! Getting it to work in my OpenBSD 6.0 with i3wm.

6.5 amd64: Modify existing certbot certificates.

Hi, It's been quite some time eh. As you can see, I still upgrade my OpenBSD system regularly but currently I do not have the time to ...