OPENBOX HOME

13. Using Xdotool to Launch Terminal Apps

    shutdown.sh
#! /bin/bash
xdotool key "super+t" &
sleep 1
xdotool key type "sudo shutdown -h 0" &
sleep 1
xdotool key "Return" &
sleep 1
xdotool key type "password" &
sleep 1
xdotool key "Return" &
fi
    ispell.sh
#! /bin/bash
xdotool key "super+t" &
sleep 1
xdotool key type "ispell" &
sleep 1
xdotool key "Return" &
fi
    tlaunch.sh
#! /bin/bash
$@
/bin/bash
Xdotool is a super useful, lightweight tool that lets you programatically (or manually) simulate keyboard, input and mouse activity, move and resize windows, etc. So, using xdotool, scripts can be quite easily constructed to carry out commands that require typing in a terminal.

For example, the spell helper ispell launches in the terminal by simply typing ispell in the terminal and clicking enter (Return) on the keyboard. The shell script ispell.sh, shown in the box on the right, put in ~/bin, made excutable and put in the menus or linked to the desktop will perform the same function with a single click. Here, xdotool key "super+t" launches the terminal (my keybinding to launch terminal), xdotool key type "ispell" types "ispell" into the terminal and xdotool key "Return" effectively strikes the enter or return key. The application inxi can be launched with a similar script with xdotool key type "inxi -F". It would appear this formula for creating shell launchers will work for just about any app launched in the terminal. For a slightly more complicated example, see the launch script to create a pure shutdown button in the box on the left.

A second recipe for putting terminal apps on a menu is to use a tiny shell script tlaunch.sh shown in the first box on the right. If tlaunch.sh is stored in ~/bin, then to put ispell in menus, for example, use:

    exec=lxterminal -e ~/bin/tlaunch.sh "ispell"

directly in the menu's config file, or .xml file, or .desktop file.