Feeds:
Posts
Comments

Posts Tagged ‘autokey’

GNOME Do is one of the coolest utilities in Linux. If you are a keyboard person you will love it. Even otherwise, do check it out as even a rudimentary use of it will tremendously improve your productivity. I have been using GNOME Do for almost a year now. I had been thinking of blogging about it for long but hesitated since it already had lot of good tutorials. I will give a brief tutorial of GNOME Do and an overview of various common tweaks you can do to get the best out of it.

What is GNOME Do

GNOME Do is , at its core, an application launcher. That is , it gives a convenient way to start some application. There are two things that makes it cool : First is that it is a self learning system which adapts to your usage and idiosyncrasies. Second is that when you add some plugins, GNOME Do will allow you to manipulate different types of objects – files, directories, contacts and more.

The discussion above may not seem interesting enough to you – Consider how you usually start an application. If you are a geek, you may use the terminal (or use the Run Application dialog using Alt-F2). There are few problems : You would have to remember the exact name of the utility and you need to type its entire name all the time. Basically, your terminal does not become intelligent automatically and figures out that when you typed "sy", you wanted to run Synaptic. You can try autocomplete or you can set aliases but it you just shifted the problem rather than solving it. The second option is to use the menu. That is really painful – Take your hand off the keyboard, click on the menu, figure out under which submenu the application is in, select it and click it – Sure it sounds exaggerated but each time you do it, it shaves some seconds out of your productive time and these seconds add up !

The plain vanilla GNOME Do waits in the background. When you type some special invokation keystroke, it springs up. You can type part of the app’s name and it automatically finds it. Even better , it gets better over time. Now a days, most of the time , I can reach the app I want in 1 or 2 keystrokes.

Comparison with Other utilities

Before discussing GNOME Do more, I wanted to discuss other related utilities. Application Launchers are very common in most OSes and there are a variety of them to select from in Linux. I have tried Launchy before – It worked sort of , but somehow I preferred GNOME Do better. One big advantage of Launchy is its cross platformness. I know there are others like Kupfer, Katapult etc but some GNOME Do seems the best to me. There is a new one in the horizon – Synapse. I am pretty intrigued with this one as it also uses information from Zeitgeist. I have been using it for past few days but it has not made me change my launcher – But given its Zeitgeist integration, I intend to keep an eye over Synapse.

Another big utility which is not really a launcher but can be tweaked to do is Autokey. Autokey’s incredible scripting support allows much more complex interactions possible. But for most basic application launching , GNOME Do will be enough (though with the help of a few plugins).

Installation and Setup

One (minor) thing to note is that GNOME Do is written in C#. I do not find anything significant there but some people may object to installing Mono based software in a Linux system. I hope that as more and more neat utilities like Banshee, Tomboy become widely used the objections will fade away. You can install , GNOME DO from Synaptic (package name is gnome-do). Or if you are a command line person use,

sudo apt-get install gnome-do

If you are interested in getting the latest and greatest GNOME Do as soon as possible , install its PPA. GNOME has been silent lately, but I found few announcements about a rewrite. Hope it keeps evolving. The name of the ppa is ppa:do-core/ppa . You can add the repository by

sudo add-apt-repository ppa:do-core/ppa

Invoking it is very simple . It is in Applications -> Accessories. If you are a command line person, enter "gnome-do" in terminal. I think by default, GNOME Do adds itself to startup applications.

Tweaking the Preferences

GNOME Do starts up and waits silently in the background. You can check the notification area in the gnome panel. The icon for GNOME Do looks like a star in a pink (or some color similar) background. The default keystroke to bring to foreground is Super+Space where Super is the Windows key in keyboard. The interface is really minimalistic which we will explore later. Now click on the arrow in the top right corner and select the preferenes.

There are four tabs (as of this writing). Check all the items in ‘General‘ tab. In the ‘Keyboard‘ tab, you can alter the keys used in GNOME Do. I think most of the defaults are fine. The simplest item to change is the keystroke to Summon the application which by default is Super+Space. You can change it to others like Ctrl+Space or Alt+Space etc. If you want to change it to something more complex , then you would have to use GNOME’s keyboard mapping utility. To change the looks, use the ‘Appearance‘ tab. I like the Glass them with black background but your preference might vary. We will discuss the plugin tab shortly.

Since there are multiple ways to use GNOME Do, I will split them into various parts in the increasing order of complexity and sophistication.

Basic Operations I – Invoking Applications

The basic way to invoke some application is to summon GNOME Do using Super+Space and then type the first few characters of the name. For ease of use, GNOME Do allows you to use the application’s name and not necessarily its actual underlying command. For eg, you type, "gnome-activity-journal" to invoke GNOME Activity Journal (GAJ) in the terminal. In GNOME Do, just entering part of "GNOME Activity Journal" will do. As you use GNOME Do frequently, it "learns" your pattern. If you use GAJ often, then after few usage , it will show GAJ after you just pressed the letter G.

Sometimes you typed part of the application name and GNOME Do keeps showing some other application. Dont worry . Just use the arrow key to see all the candidate list. Lets say, you want to invoke "Gettings Things GNOME" (GTG) and typed GNOME. It might show GAJ as its first result. You can either keep typing or press the arrow keys and select GTG to invoke it.

Tips for using GNOME Do Effectively – I

Even though, we are still scratching the surface of GNOME Do, you can gain immediate productivity gains. You need not use the menu at all to invoke, say, Gedit, Firefox, Open office , VLC player etc. All of them can be invoked from GNOME Do and just by few keystrokes. Neat – isnt it ?

One thing that you will notice is that when two applications share some common prefix , there are two ways to handle it. Either you type extra characters to disambiguate or you use the arrow keys to select from candidate list. It is important to know when to do what. GNOME Do also has a neat feature to mitigate this issue. Basically, it allows you type any ‘subsequence’ of the application name instead of its exact prefix. For eg, if the application’s name is abcdef, you can invoke it as abcd.. or abef or adf.. etc. Basically you can type part of its name in mixed order and GNOME Do will still figure out the application. Sooner or later, you will develop your own set of strings to disambiguate. There are lot of apps that start with the string "gnome-". I usually ignore the first string and type the next word. So, to disambigute say "GNOME Activity Journal" and "GNOME Terminal", I will use say journal for GAJ and terminal for the later. The idea is to find some string which uniquely identifies the application. There is another neat way to do it using Aliases which we will see later.

A related feature is that GNOME Do allows most of the navigation keys in the candidate list. So you can use keys like Home, End , Page Up , Page Down to zip through the list.

Basic Operations II – Performing Tasks

GNOME Do is a task oriented application launcher. There are two idiomatic ways to perform some tasks. ie you can invoke tasks as ,

<Items> <Action>

Or

<Action> <items>

Lets say you want to chat with X. In first way you say as ‘X and Chat’. In second way , you say ‘Chat X’. GNOME Do allows both ways to perform the task.

You can notice that GNOME Do has two panes. When you were invoking applications, the application name came up in the first pane. If you look closely now, the second pane will contain the word ‘Run’. Now type something else like Desktop. Notice the second pane, the action changes to "Open". Here you are treating pane 1 as items pane and pane 2 as actions pane. One thing to note is that both of them have different alternatives. Pressing arrow keys on first pane will show other alternative applications (items) and doing it in second pane will show other possible actions. In the plain GNOME Do has a restricted set of actions, but we will increase it soon. The same discussion applies when you swap the panes and use Action in pane 1 and item in pane 2.

To move between the panes use the tab and shift+tab keys. Use the arrow or other navigation keys to select other items/actions. If you want to cancel what you are typing , press Esc. Remember that Esc clears everything you typed. If you want to modify selection from just one pane, use the Shift+tab key. Lets say you are in pane 2 and selected some action. Pressing Esc now resets everything and gives you a clean slate. Pressing shift+tab, just returns it items pane where you can select some other item without changing the action selected. If the first pane is empty, pressing Esc closes GNOME Do.

As of now, you know two things. Invoking applications by typing their name and typing some item and select some other action to perform on it. These will constitute around 80-90% of your interaction with GNOME Do. When we add new plugins, all they do is increase the variety of either item types to operate on (eg email contacts in addition to files) and new actions to perform on them (eg open a terminal in a folder instead of just opening it in Nautilus).

Another important idea is that of the ‘Extra’ pane. Most of the time you will be working with just two panes. For some rare actions you may need more of them. Consider for eg renaming a file. You need a pane to give the action (rename), one to select the file and another to give the new name. The new name is entered in the extra pane. There are few other actions that use the extra pane. When you select them, they automatically extend the GNOME Do screen to include the third pane.

Tips for using GNOME Do Effectively – II

Sometimes, you would want GNOME Do to shut up and wait for your full text instead of showing possibilities. One eg is when you type an actual command which is not listed. Or may be you want to send a status message to twitter and do not want GNOME Do to interpret as something else. Typically, Do will try to find matches and if it does not find any , it will give up . You can find this, when the keystrokes are show in the upper half of item pane like superscripts in tiny font. Basically, GNOME Do has entered its text mode where it will wait for you to type the text. One way to force it to go to text mode is then "." (dot) operator. Pressing period key will immediately move to text mode where you can type any thing you want. Of course, you need to press tab to go to action pane after typing your text.

The next common thing involves multiple items – Either you want to perform single action on multiple items or many actions on a single item. Lets say, you want to open file1,file2… file10.txt. Type the word ‘file’ in items pane. Press the arrow key to see all the candidates. Since all the files shared the same prefix, GNOME Do will show all the files (file1 to file10) as candidates. Now select the first file (file1) using arrow keys and press the "," (comma) key. The item’s icon will change to a "+" sign. Now move down and select file2 to file10. Remember to press "," on each of them. Now press tab to go to the next pane and select the appropriate action. This will cause all the files to get opened in bulk.

The method to perform multiple actions on same item is similar. Lets say you want to open Desktop in Nautilus and also open a terminal there. In the items pane, select the file. Go to the actions pane using tab. Press the arrow key to see all actions. Select the first action and press "Shift+Enter". Now do the same for other actions. You will see GNOME Do triggering one action after the other on the same item.

Plugins

Plugins make GNOME Do even more powerful. There are literally tens of plugins covering all varieties of tasks. Plugins either introduce new actions on items or new item types. I will discuss about plugin development later in the post. In the mean while, let us see some of the coolest plugins and how to use them to improve productivity.

There are broadly two types of plugings : Official and Community. The distinction does not matter much to a typical user. To install a new plugin, press Super+Space , click the arrow , select the Preferences option. Now go to the ‘Plugins’ tab. Select "All Plugins" from the dropdown.

Neat Plugins

1. Files and Folders plugin

This is the most useful of all plugins and I use it heavily. The basic functionality allows you add some specific folders and files to be added to the GNOME Do index. By default, GNOME Do only indexes folders specified in the Nautilus bookmarks. If you access some files very frequently, then use this plugin to add them. Lets say, I have my research files in some path. If I want to access them via GNOME Do, all I need to do is to add the folder to this plugin. Now when I type a prefix of the file names in this folder, they will be opened.

This plugin also has a Configure button. Clicking it will take you to a dialog which contains ‘Indexed folders’ and ‘Ignored Folders’. You can add as many folders as you want and also mention the depth to index. A good set of folders is to include your home , Desktop and other folders that you access frequently. If you dump most of your stuff in Desktop, then increase its depth. By default, it does not index hidden files which makes sense. Do not index folders which have too many files in them as it defeats the whole purpose.

This plugin also has other amazing featues – for eg It allows you to browse a folder . Type a folder name and press the right arrow. It will show all the contents of folder in the candidate list. It also has options to copy or move a file. For other features look at File and Folder plugin’s wiki url.

2. Locate and Tracker plugins

This two plugins are very closely related to the previous plugin. There is usually a tradeoff between using Files and Folders and locate plugin. You should not use Files and Folders to index every folder in your computer. That will make GNOME Do slow and kinda defeats the whole purpose. So index folders and files that you access frequently use the previous plugin. For files or folders that you access infrequently, use this plugin. Basically, this is a wrapper over the locate command. For eg, I have indexed the files that I frequently use for posting blogs. I also have few folders where I store supporting stuff. I usually use the locate plugin to find them.

There are two ways to use the plugin. The easiest is to select ‘Locate Files‘ action in first pane and type the query word in second pane. If you do it the other way, Do will try to interpret it as a file. So in that case you are better off going to the text mode – type the dot in first pane , go to text mode, type the query , press tab to go to next pane and then select locate files action.

The tracker plugin allows you to do full text search for the keyword you gave. Basically, instead of searching for file names, you use file content to search.

3. Rhythmbox and Banshee plugins

Whether you are a Rhythmbox or a Banshee person, GNOME Do has plugins that allow you to control these applications. Once you install, they make the entire music library searchable. You can select an album and play it. There are also basic actions to pause, play , go next and previous. If your keyboard has multimedia keys then I do not see any reason to use these actions. The ability to select an album and add them to play queue is really neat though. If you have both the plugins, sometimes you can get confused – Based on whether they come from Banshee or Rhythmbox , the option to play it in the other player may not be available.

4. GNOME Terminal plugin

This is a simple plugin which has two options. If you selected some file or folder and select the ‘Open Terminal here‘ action, it will open a new terminal and cd in to the folder (or parent folder for a file). If it is a executable file or script, you can use ‘Run in terminal‘ command to invoke it. This is slightly different from the Run action as it starts a terminal and then invokes the command.

5. Firefox and OpenSearch plugins

These are two nifty plugins if you use Firefox. Firefox plugin indexes all your firefox bookmarks and allows them to opened in your default browser using the ‘Open URL’ action. OpenSearch reuses the OpenSearch plugin in your system and makes it accessible through GNOME Do. For eg , if you installed say wikipedia opensearch plugin, you can enter a keyword and search it in Wikipedia. It will open your default browser to show the search results.

The way it works is a bit tricky. It recognizes only user installed OpenSearch plugins. This means the default ones that come with Firefox like Google, Yahoo or Bing dont work out of the box. To fix it, manually copy /usr/lib/firefox-<version>/searchplugins/en-US/*.xml to ~/.mozilla/firefox/<yourprofile>/searchplugins/ . I have used the en-US which I think covers most opensearch plugins. If your plugin uses some other locale, copy them too. Now enter the keyword to search (preferrably in text mode) and use the ‘Search Web’ action and select the appropriate OpenSearch provider.

6. Window Manager Plugin

This is a plugin that is useful sometimes. Typically you use GNOME Do to invoke applications. But once the application is invoked, then this plugin adds some more window management options like Close, Minmize, Maximimze etc. I typically use either the ‘Focus‘ option to bring to front (which is very useful if you are also using docky) and ‘Move Window To‘ some other workspace. If there are multiple instances running, type the application name and then use the arrow key. The name of the application will have a tree like structure showing all the instances which you can select using navigation keys and then perform the appropriate window action.

7. Pidgin , Evolution and Thunderbird plugins

If you are using Pidgin or Evolution, you can use these plugins. These add Pidgin contacts and Evolution/Thunderbird mail contacts to be indexed by GNOME Do. For Pidgin contacts, you will see a Chat action that opens a new window. For Evolution contacts, it opens up a new mail to window. For some reason it does not work for Thunderbird even though it uses xdg-email internally. But still it is cool to say Chat X or Mail Y !

8. GNOME Screenshot Plugin

This is a simple plugin but I added it as the plugin wiki seems to be wrong. For using this plugin enter ‘Current Window‘ or ‘Whole Screen‘ as item and ‘Take Screenshot’ as action. Optionally select a timer. I usually use when I want to take some snapshot for my blog posts. This is much easier that opening screenshot and setting the values manually. This currently does not work for me . When I find the reason, I will post back.

Plugins that are not working for me

GNOME Do has few plugins that do not seem to work for me. For eg, the ‘aliases’ plugin seems very promising but never worked for me. It allows you to enter an alias for an application and then use it to invoke it. Its a great idea but surprising does not work.

Two other plugins that I wish that worked are the Thunderbird and Screenshot plugin. Thunderbird correctly indexes all the mail contacts. When I use the Mail action, I get an error that says ‘gvfs-open: file:///home/blah/xdg-email%20%20’emailid’%20%20%20%20%20: error opening location: Error stating file ‘/ home/blah/xdg-email ’emailid’ ‘: No such file or directory . I have been intending to work it for quite some time but never got around it. May be I will do it this weekend. The Screenshot plugin also gave a similar error – hopefully one change will fix them both. I will update the post once I got some results.

Geek Stuff

Following are some misc stuff that are of interest to geeks. Feel free to ignore this section if not interested.

1. All plugins in GNOME Do are written in Mono and use Mono.AddIns framework. There are a few potential plugin ideas to explore. I will give it a shot during my vacation. Currently, there exists plugins that index firefox bookmarks and use Firefox’s opensearch details. Something that indexes Chrome’s bookmarks should be neat. It would be useful to fix the Thunderbird plugin to support mail and attach actions. Same holds for Screenshot plugin. Another plugin that needs fixing is the Alias plugin. Now that , Empathy has become the default plugim, I think there is a need to have a Empathy plugin similar to Pidgin .

2. Running gnome-do in a terminal is a great way to know what is going on in the background. Probably a good debugging idea too !

3. By default, GNOME Do indexes all the menu items in GNOME Menu. If you want to add some other entry, add a ‘.desktop’ file to ~/.local/share/applications. You can use other desktop files as reference.

4. If you added a script (and indexed that folder via Files and Folders plugin or added a .desktop) file, make sure that it has executable bit turned on. Else GNOME Do will not show ‘Run’ action and will show only ‘Open’ action.

References

1. GNOME Do Main Wiki Page : Contains basic information about installation, usage and other stuff.

2. Plugin Doc : Contains documentation for few plugins.

3. GNOME Do White Paper : Contains few technical details and the motivation behind GNOME Do.

4. Writing Plugins : Basic information about writing plugins.

Conclusions

GNOME Do is a very neat utility and can dramaticaly improve your productivity when used with right set of plugins. I hope this post gave you some tips on using it more effectively. Good luck with GNOME Do !

Advertisements

Read Full Post »

In this post, I talk about one of my favorite utilities I use regularly – AutoKey. AutoKey is a real life saver and a great productivity boost for me. There are not much articles about AutoKey and even those few cover very few of its features. I intend to talk about some of my favorite features which I use regularly. I use AutoKey’s GTK version in Ubuntu but most of the points in the post will be applicable to other Linux variants and KDE.

What is AutoKey

AutoKey’s homepage describes it concisely as : "AutoKey is a desktop automation utility for Linux and X11. It allows the automation of virtually any task by responding to typed abbreviations and hotkeys. It offers a full-featured GUI that makes it highly accessible for novices, as well as a scripting interface offering the full flexibility and power of the Python language.".

If you have used AutoHotKey in Windows, then you will be immediately comfortable in AutoKey. (If not, you should check it out !) .  AutoKey uses Python as the scripting language instead of AutoHotKey’s custom scripting language. But the potential and functionality are very similar.

AutoKey can be used in multiple scenarios :
a) Text Substitution : Replace a short abbreviation with a long expansion. Eg adr with your full address.
b) Hotkeys : If you are a keyboard person like me, use it open various program. For eg I use windows+c for opening chrome, windows+g to open  gedit etc. Alternatively, you can make AutoKey "send" hotkeys to the applications. (Eg make it press ctrl+s automatically).
c) Automation : AutoKey supports Python scripts and has a very useful API’s to control windows, clipboard and mouse. So you can use it to automate any thing you can imagine !

The biggest advantage of AutoKey is that it works across all applications. So I can add a keyword which expands to a code snippet and use it in multiple applications – say in vim and also in gedit without any extra work.

Installation

You can read all about the utility at AutoKey’s homepage. The Google code page is the recent (and active) one even though most links in net points to a sourceforge page.

There are many ways to install AutoKey and it depends on your OS. For Ubuntu, the easiest way is to install using the update manager. I would suggest using the update manager as it will install the dependencies automatically. If you want to be in the latest code then the best solution is to add AutoKey PPA to your system. Instructions for adding the PPA is in the linked page. I would recommend getting the latest version (0.70) as it has lot of new features and some important bug fixes. Of course, if you use any other Linux variant, you can always install from AutoKey’s source at the download page.

Starting AutoKey

You can start AutoKey in Ubuntu by Applications -> Accessories -> AutoKey. Or in command line (for GTK) as /usr/bin/autokey-gtk. Once it is started , you will see an blue icon with "A" in the tray.

Once you start using AutoKey , you will prefer to start it when the system starts. For Ubuntu (GTK) AutoKey, System -> Preferences -> Startup Applications , enter "/usr/bin/autokey-gtk" as an additional startup entry. Note : AutoKey also has an option in its preference to start automatically but it did not work for me.

Some Basics

AutoKey appears in the tray as a blue colored icon with "A" in it. Most of the time, it runs passively , reading your keystrokes. Right click on the icon and make sure that the checkbox "Enable Expansions" is checked. Only then AutoKey will perform the expansions.  To make any changes, you need to access its configuration dialog box. To get it , right click on the AutoKey icon and select "Configure".

The configure window will look like this.

AutoKey Usage  : Phrases

Phrases are the easiest way to start with AutoKey. You can consider this feature as a powerful text expansion. For eg you can enter the string "adr" and get it expanded to your whole address.

Phrases : Example 1
Lets take a simple example. Whenever I type the string "akr" , I want it to expand to "Auto key rocks !" . To get this , open the AutoKey config editor. Create a new phrase by File -> Create -> New Phrase (Or Ctrl + N) . Give the phrase a valid name. (Eg AutoKey). In the phrase box (the large text box – which is actually an editor !) , type "Auto Key Rocks !". In the "Phrase Settings" section, click on the "Set" button near "Abbreviation". Type the abbreviation as "akr" . Your screen will look like the image at the bottom. Click "OK" and click on "Save" button. Congrats , you have created your first phrase.

Lets now test it out. Open gedit (or kate or some editor) and type akr. Watch it expand to "Auto key rocks !". Now try it in vim. Try it in Firefox. Try it in Open Office. Watch it work at all the places.

Phrases : Example 2
Now let us make it slightly more complex. Lets say we want a tab in between each word. (Auto    Key    Rocks    ! ). To do that, select the phrase you just created. In the editor box, type the following. "Auto<tab>Key<tab>Rocks<tab>!" . Thats right. When AutoKey sees <tab> it expands it to the actual tab character. Now save the phrase again and try it .

Tab is not the only hotkey that AutoKey supports. It supports virtually all the special keys in the keyboard. You can get all of them at AutoKey’s Hotkey’s page .

Phrases : Example 3
Another of my favorite feature is "Match phrase case to typed abbreviation" . To try it out, give "Auto Key Rocks !" (ie remove those tabs) in the editor box. Click on "Set" button of "Abbreviation" . Select the checkbox “Match phrase case to typed abbreviation". The next checkbox "Ignore case of typed abbreviation" should be automatically become checked. If not check it. Save the phrase. The dialog must look like the image below.

Now experiment with various ways of typing the abbreviation.
"akr" auto key rocks !
"Akr" Auto key rocks !
"AKr" Auto Key Rocks !
"AKR" AUTO KEY ROCKS !

Phrases : Example 4
Another thing to try is to give hotkey to the phrase. Of course, it does not make much sense for this small phrase. If you have a large paragraph and want it copied in a single command , then hotkey is the way to go. Again , hotkeys are very useful when using Scripts. (Which I will discuss shortly)

Before setting a hotkey, the usual caveats apply – make sure it does not clash with other applications’ functionality (Eg ctrl+s for expanding phrases is a bad idea !) . Also if you are using Hotkeys make sure it is memorable.

As a simple example, lets make "Auto key rocks" when we press ctrl+alt+q. To do that , click "Set" near "Hotkey". You will get a dialog. Click on "ctrl" , "alt". Now to set "Q" , click on "Press to set" and type "Q". Press "Ok" and save the phrase. Your screen will look the image below  . Now type "ctrl+alt+q" in any application and watch it become "Auto key rocks !".

Phrases : Example 5
Let us suppose you want your abbreviation to work only in one application. This can be achieved using "Window Filter". Let us take an example. You want akr to be expanded in Gedit only. Notice that any document (new or existing) opened in Gedit ends with the word gedit. We will use that as our filter. To achieve that , select the phrase and click on "Set" near "Window Filter".  Enter ".*gedit" as the filter. There are two things to note here .
a) The filter is actually a regular expression which has lot of expressive power.
b) The regular expression must match the whole window name. Just having "gedit" will not match a gedit window.

Phrases : Example 6
One of the common ways I use Phrase is to expand code snippets. For eg when I type cppincs , then I automatically the following snippet. It works whether in vim or in gedit. (If you use primarily vim, then checkout vim plugins like snippetsEmu or snipMate ).

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
return 0;
}

Phrases : Example 7
You can use AutoKey to enter username and password automatically. A simple example is to have a phrase like “username<tab>password<enter>”.

Misc Phrases Features

There are some other options in Phrases menu. These features are applicable to scripts also.

a) "Always Prompt before pasting this phrase" – If checked, when you type the abbreviation , you will see a confirm from AutoKey. Only when you confirm it will be expanded. I doubt , you will ever select it.
b) Show in Tray menu : If you select this option, your phrase will be visible when you right click on the AutoKey icon. I guess , this will be useful when you dont assign an abbreviation or hotkey for a phrase.  But again, why will you ever do that ?

Misc Abbreviation Features

When you click on "Set" near "Abbreviation" you will see lot of options. Again, the same description applies to scripts also.

a) Remove typed abbreviation : It is usually checked. This means you are actually asking for a text substitution. ie "akr" becomes "Auto key rocks !" . If you uncheck it, then "akr" becomes "akrAuto Key Rocks !".
b) Omit trigger character : Typically the phrase is expanded when you type a space or press enter. If you select this option, they will be ignored.
c) We already discussed "Match phrase case to typed abbreviation"  and "Ignore case of typed abbreviation" in Example 3.
d) "Trigger when typed as part of word" and "Trigger immediately"  : These two work in conjunction. If both are checked, the abbreviation is expanded immediately without waiting for space or enter.

AutoKey Usage  : Scripts

Scripts are the coolest feature in AutoKey. AutoKey uses Python as the scripting language for automation. If you don’t know Python, you should really learn it ! AutoKey has an excellent set of API to make your code a breeze. Scripts come into play when you want to do more complex things than simple substitution. Examples include : bringing the current time in the document automatically, adding selected word automatically to Google calendar etc. In fact you can even show some rudimentary GUI to user. Most of the features in scripts are similar to phrase features.

Scripts : Example 1
This example is from AutoKey’s sample scripts page. Lets say you want to bring the current date and time whenever you typed the word "date" in any     application. File -> Create -> New Script (or Ctrl + Shift + n) . You will be see a editor with full Python code highlighting. Enter the following script

output = system.exec_command("date")
keyboard.send_keys(output)

The screen should look like this :

Note that in this case, system was already imported. If you want to use some other package, you might want to import it first. Give "date" as the abbreviation. Save the script and type "date" in any application and watch it magically become current time (Eg Wed Apr 14 21:14:27 CDT 2010 ) . Of course, you can have a hotkey assigned for the script too !

Scripts : Example 2
One of my favorite way of using AutoKey is to use it as a way to invoke applications. I am more of a keyboard person and like to do everything without touching the mouse. For eg , when I press "super+c" , Chrome gets started. Lets try it now.

In a new script , press the following code and assign "super+c" as the hotkey. Super is nothing but the windows key on the keyboard. After saving it , when you press "windows(super) + c" , Chrome starts !

import subprocess
subprocess.Popen(["/usr/bin/google-chrome"])

You can note that there are two ways of invoking commands. "system" is the old way of invoking it. It works well when you want to wait for the output of the command. "subprocess" is much more flexible. I have used "Popen" which is typically used to start a program and you want to wait for it to end.

Scripts : Example 3
Alternatively, you might want to use AutoKey to open some folders or files based on a hotkey. Eg open your "Ubuntu One" folder with a hotkey or open some excel sheet. A generic way (Obtained from the discussion here ) is given below. xdg-open intelligently, opens the file/folder using the appropriate viewer/program.

import subprocess
subprocess.call([‘xdg-open’, ‘PATH_TO_FILE_OR_DIR’])

Scripts : Example 4
There are lot of interesting ways to use the full power of Python. Some clever usage can be seen at Favorite scripts 1 ,  and Favorite scripts 2 .

Scripts : Example 5
AutoKey has a powerful API to control windows, clipboard, mouse etc. For eg, you make a particular window come to foreground (see window.activate) , get the selected text, get contents of clipboard, add a text to clipboard etc. You can check the AutoKey API reference.  You can also check out some sample scripts .

Another neat feature is to provide a lib folder and AutoKey will import all files in that folder. I have not tried this feature, but I think it should work. To get that Edit -> Preferences -> Script Engine.

Folders

AutoKey uses folders to organize the phrases and scripts. You can either create a new top level folder or some nested folders. This concept is quite easy to use. I group the phrases and scripts based on their functionality and intent. You can use any organization that works for you.

Trays

The concept of tray is another useful feature – Although, I rarely use it. There are two ways to add a phrase or script to the tray. First is to add the phrase/script within the "Tray Phrases" folder. Other way is to check the checkbox "Show in tray menu" (for both phrase and script). In both the scenarios, when you right click on the AutoKey icon, you will see them. My guess is that this will be useful if you did not set a hotkey or abbreviation.

Preferences

AutoKey has a intuitive preferences menu. Common things to do are :
a) Enable "Prompt for unsaved changes" checkbox in "General" tab. If unchecked, the phrase/script changes are automatically saved.
b) Also check "Enable undo by pressing backspace". This means when you want to type a text which is a abbreviation (eg akr) without getting expanded, then you type the string,let it expand and press the backspace immediately. It will give the abbreviation without the expansion.
c) Another thing to change is default hotkey to get AutoKey’s config window. It is usually ctrl+k which interferes with Firefox’s search button.
d) Check out other options and enable as you feel fit.

Miscellaneous Stuff

1. Autokey works by catching you keystrokes and doing the expansion or script execution. This has many implications which you will notice when you use AutoKey a lot. For eg when you copy paste a text with an abbreviation , it will not expand as you did not "type" it. Similarly you can cause a abbreviation to be not expanded if you use your left/right keys. Of course, using backspace within an abbreviation still results in proper expansion.
2. Previous versions of AutoKey had a nifty hotkey called cursor which will place the cursor at that position. It is not supported. For  a workaround , see this Ubuntu forums thread. To give it here ,

firstPart = "First part of the text. Cursor ->"
secondPart = "<- second part"
keyboard.send_keys(firstPart + secondPart)
keyboard.send_key("<left>", len(secondPart))

3. If you want to see all the AutoKey topics and responses , check out their mailing list topics.
4. AutoKey now uses a json file for configuration. It is located at ~/.config/AutoKey/AutoKey.json. Enjoy playing with it ! This also means that if you want to use the same settings across users , just create a symlink to the same file. If you want to share across multiple machines use Dropbox or Ubuntu One. For more details, check this AutoKey thread.
5. If you face any issues when using it, follow the instructions at the Troubleshooting page before shooting a mail. That said, I have to say that AutoKey mailing list is very active and helpful !
6. This is a post from LifeHacker on snippits , another tool similar to AutoKey. I would not recommend it (as I had  a hard time even installing it). But the point is , you should be able to use most of the things done in the video and more using AutoKey. Use that video as an exercise for testing your AutoKey skills 🙂
7. There is another project called IronAHK that is going on which brings AHK to Linux. It is not yet ready for prime time. If you are a AutoHotKey user , may be you will find it useful.

Good Discussions In AutoKey’s Mailing List

I notice that AutoKey’s mailing list occasionally bring up some creative way of using AutoKey. I hope to keep this section as a live one which catalogs the discussions that bring out a new facet of AutoKey. . 

1. Can I exclude windows in Window Filter?

Yes. See here .

2. How to get a script to invoke an abbreviation ?

See here .

3. Restrictions in using modules in AutoKey scripts :

See here and here.

Acknowledgements

I have liberally used resources from AutoKey’s wiki pages and its mailing list. I learned lot of very interesting points from AutoKey’s mailing list. I have linked to some of them and given the essential point of the thread in some places. If you are using AutoKey , then you must join the list. It is a very helpful and active list.

In conclusion , AutoKey is a very neat utility . Clever use of it will tremendously improve your productivity. I hope this post helped to use it better ! Have fun with AutoKey !

Update [04-15-2010]: Corrected a mistake  pointed out by Chris. If “Prompt for unsaved changes” checkbox is unchecked, changes are saved automatically. You don’t lose the changes as I wrote.

Add to DeliciousAdd to DiggAdd to FaceBookAdd to Google BookmarkAdd to RedditAdd to StumbleUponAdd to TechnoratiAdd to Twitter

If you liked this post , please subscribe to the RSS feed.

Read Full Post »