Answers

10 min read

Got a burning question about open source or the kernel?

Neil Bothwick believes that Whatever your level, email it to answers@linuxformat.com he is the reincarnation of Alan Turing.

Topics
Topics

Q Hotting up Debian

I’ve started using Linux through Debian and so far so good. However, something that’s pretty essential to how I use my computer is the various shortcuts AutoHotKey provided in Windows.

In AutoHotKey, I had a script that played an MP3, located in my files, every 20 minutes, which was an alarm notice for me; I had various text replacement tools that enabled me to enter long strings of text wherever I happened to be typing by just typing an arbitrary code phrase and pressing Space; and I had macros that would do things like run a Java file from the command prompt just by pressing F9.

A Welcome to the world of Linux. One of the many differences between Linux and Windows is that there is usually more than one way of doing something in Linux. This includes fundamentals such as the desktop environment. You do not say which desktop you are using, but many have the ability to respond to hotkeys built in. If you go into your desktop’s main configuration window, you will almost certainly find such an option that allows you to bind actions to keys. Those actions could be as simple as inserting some text or could run a command.

If you are looking for a method independent of your desktop, there is Autokey (https://github.com/autokey/autokey). Although we have given the homepage here, that is not how you install software in Linux; instead you do it from the distro’s software manager, usually Synaptic on Debian. Autokey does most of what you describe and the wiki linked from the homepage gives clear instructions.

One thing that you do with AutoHotKey that is not covered by Autokey is run a command at regular intervals. One of the mantras of the Unix/Linux world is that each tool should do one thing and do it well. Responding to hotkey events is handled by Autokey, or the desktop’s own equivalent; running scheduled tasks is handled by Cron, software designed to do just this. Cron is controlled by files called crontabs, there is one to run system commands, plus each user can have their own. You create or edit a crontab file with:

$ crontab -e

or

$ sudo crontab -e -u username

Autokey can be used to insert text or run commands from a key press.

The first method is preferred but some distros are set up to only allow the root user to create crontabs, so we have to use sudo. This opens a crontab containing only explanatory comments, to which you can add a line to define each command. Each line contains six items, the first five are the minute, hour, day of month, month and day of week, where a * means ‘any’. The rest of the line is the command. For example:

*/20 * * * * mpg123 /path/to/sound.mp3

This plays the sound e