Saturday, May 30, 2015

Creating custom commands in Linux

One of programs I often use is Winbox, tool for managing Mikrotik routers. So I want to make it fast and easy to run it from anywhere.

Winbox is windows application and requires Wine to run, so you cannot simply type in winbox and run it. We are going to do just that.

First download winbox or any application you want and place it somewhere. I don't like using default Wine location in ~/.wine/drive_c/Program Files/ and I make folder just for my apps like home/locodog/programs

So, you installed Wine with sudo apt-get install wine or  yum install wine or how ever you install applications on your distro.

To run winbox simply by typing winbox into terminal or Alt+F2 Run screen, open console and type this line:

echo "/usr/bin/wine home/locodog/programs/winbox.exe" > winbox

/home/locodog/programs/winbox.exe is actual location of winbox.exe and it can be where ever you want.
Now let's make newly created file winbox executable by doing

chmod +x winbox

At this point you can run winbox by typing complete path to it, but to be able to run it from anywhere copy file to /usr/local/bin/  or move it there if you don't want copy of it with

sudo mv winbox /usr/local/bin

That's it, you can now run your winbox app from anywhere.


Microsoft Natural Keyboard 4000 in Linux Fedora 21 LXDE

Microsoft Natural 4000 is great keyboard, but on Linux, well at least in my case multimedia keys didn't work out of the box. I had to figure out how to make them work.

First, I wanted to use custom shortcuts for buttons like HomePage, Search, Email and those numbered 1-5.

To find out does X detects your keypresses in console start xev.

xev | egrep -o "keycode.*\)"

While program is running press keys you would like to map. Result should be something like this:

keycode 195 (keysym 0x1008ff48, XF86Launch8)
keycode 195 (keysym 0x1008ff48, XF86Launch8)

Keep in mind that xev detects key press and key release as separate events. What we need from here is XF86Launch8.

Open file ~/.config/openbox/lxde-rc.xml in your favorite text editor and find line with </keyboard> in it. You need to write your keybindings between <keyboard>  and </keyboard>. I like to add mine just above </keyboard> because it's easier for me to find it later.
Now insert actual keybinding. This particular key I want to use for starting teamviewer.

<keybind key="XF86Launch8">
    <action name="Execute">
      <command>teamviewer</command>
    </action>
  </keybind> 

 Save file and in console execute openbox --reconfigure

For more info check out http://wiki.lxde.org/en/LXDE:Questions#Modify_mouse.2Fkeyboard_bindings

Zoom slider


Problem with zoom slider is that xev doesn't detect anything when you move it. After reading many posts I found what works for me.
Create file /etc/udev/hwdb.d/70-keyboard.hwdb
You will need to create folder hwdb.d because it doesn't exist.

with this content

# Microsoft Natural Ergonomic Keyboard 4000
keyboard:usb:v045Ep00DB*
 KEYBOARD_KEY_c022d=zoomin
 KEYBOARD_KEY_c022e=zoomout

Instead of "zoomin" or "zoomout" you could give keys different function like pageup and pagedown if you want to use this key for scrolling through page. Or even up and down to scroll line by line.
Save file and run sudo udevadm hwdb --update after that you might need to unplug and plugin your keyboard again or if that doesn't help, reboot.