Autohotkey for Linux

In a previous blog I showed how it’s possible to make a simple GUI that duplicates some of the behaviour of AutoHotKey, the scripting utility for Windows. AHK is very good but I was confused to hear that “sadly nothing is available like this in Linux” which is, as I thought, simply untrue. Just as in AHK, there are many ways to write functions that take highlighted text and make it into an HTML link, or IMG HTML so it can be pasted back into a X. Shortcut Keys can fill the paste buffer with often used text like email addresses and links and can move windows around and resize them by the pixel or to predetermined sizes (for The Gimp for example). This is achieved using a mixture of Tcl, Tk, Zenity and Bash scripting along with various X utilities.

Note: The following scripts require the presence of “xsel” and “zenity”. Install in the normal way you use for your distro.

Make some text into HTML

I use this script to quickly make links in Drupal for content that allows HTML formatting, of course you could us it for any repetitive task.


#!/bin/bash
# Make URL - Barney Holmes, 2010
# Usage:
# * Highlight the text using the middle mouse button.
# * Activate the script on the command line or link it to a keyboard shortcut. See System -> Preferences -> Keyboard Shortcuts -> Custom Shortcuts (Lucid).
# * Enter the URL link into the script GUI.
# * The paste buffer is now full with an HTML formatted link.
# * Paste with the middle mouse button.
link=
buffer=`xsel -o`
url=`zenity --title "Make HTML URL" --entry --text "Highlighted text = \"$buffer\" \nLink will be placed in paste buffer. Use middle mouse button click. What is the URL ( http:// ) link ?"`
rc=$?
if [ "${rc}" == "1" ]; then
 echo User cancelled operation.
 exit 1
fi
echo -n "<a href=\"$url\">$buffer</a>" | xsel -i

I have the script connected to a Win Key & L key press.

Make Image link into HTML

#!/bin/bash
# Make image HTML - Barney Holmes, 2010
# Usage:
# * Highlight the text using the middle mouse button.
# * Activate the script on the command line or link it to a keyboard shortcut. See System -> Preferences -> Keyboard Shortcuts -> Custom Shortcuts (Lucid).
# * The paste buffer is now full with an image HTML.
# * Paste with the middle mouse button.
buffer=`xsel -o`
echo -n "<img src=\"$buffer\"></img>" | xsel -i

This one uses a Win Key & I key press on my system.

Paste Often Used Text Snippets

#!/bin/bash
# Make URL - Barney Holmes, 2010
# Usage:
# * Activate the script on the command line or link it to a keyboard shortcut. See System -> Preferences -> Keyboard Shortcuts -> Custom Shortcuts (Lucid).
# * Paste with the middle mouse button.
echo -n "contact@server.co.uk" | xsel -i

Just replace the text with your own and duplicate the script as necessary. I have my snippets linked to Win Key & 1,2,3 ... number keys. The next blog in this sequence will show how to move and resize windows using keyboard shortcuts.
Advertisements

One thought on “Autohotkey for Linux

  1. Pingback: Copy & Paste Between the Linux Console and GUI | DJ'ing, Music, Humour, Life

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s