You are not logged in.

#1 2016-09-27 09:06:30

1Try
Member
Registered: 2016-07-21
Posts: 16

Application to bind commands to words

Hi everybody,
What I would like to achieve is the same thing that AutoHotKey "hotstrings" do on windows.
e.g. typing "open" everywhere in the system (terminal, browser, dmenu ecc...) or in a specific program triggers an event.

Is there any program that allows anything close to this?
Thank you for your help in advance

Edit:
Sorry I forgot to mention the fact that I've already (and still am) reading some material on the forum. In particular (https://bbs.archlinux.org/viewtopic.php?id=191961f) and that my desktop environment is i3!

Last edited by 1Try (2016-09-27 09:30:24)

Offline

#2 2016-09-27 09:37:10

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: Application to bind commands to words

The best-known example is probably `xdg-open`, which is also used by lots of other applications.

On the other hand, `xdg-open` does not seem to be very popular among quite a few people (e.g. I consider it to be rather slow, and the configuration is not very CLI friendly), so they wrote their own version (e.g. this would be mine). After all, it's just mapping MIME type → application.

If you choose to write your own script, you could take a look into ~/.mailcap, which was originally targetted at mail applications (e.g. mutt), but seems like a sane configuration format to me.

Last edited by ayekat (2016-09-27 09:39:06)


pkgshackscfgblag

Offline

#3 2016-09-27 09:56:07

1Try
Member
Registered: 2016-07-21
Posts: 16

Re: Application to bind commands to words

Mmm I didin't know about any of these terms: xdg-open, MIME, ~/.mailcap so thank you. However after reading https://wiki.archlinux.org/index.php/de … plications it seems that xdg-open's purpose is to set default applications for specific extensions not creating systemwide hotstrings that trigger events. Or maybe I haven't understood a single word of the wiki ahahha

Offline

#4 2016-09-27 11:00:51

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Application to bind commands to words

I think you should (have) put a little more effort into describing what you want, because I'm probably not the only one who doesn't want to take the time to study a Windows application first.

Edit: I suppose adding the link to that other thread more or less completes the description. I still don't have any good suggestions, though.

Last edited by Raynman (2016-09-27 11:04:20)

Offline

#5 2016-09-27 11:58:19

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Application to bind commands to words

Basically what you are looking for is a keylogger with a limited buffer/storage.  Once you have that the ability to execute a given command whenever the tail end of the buffer matches a given string of keys is trivial.  But getting an X11-wide keylogger that doesn't have horrible side effects is anything but trivial.

You'd be *far far* better just using something like dmenu and binding it to a key.  I have my own dmenu-like tool bound to the "Widows menu" key on my laptop.  So I could type <MENU>open<ENTER> and it would respond with whatever I configured it to do for the "open" command.

This approach would require 2 extra key presses on every use.  But it would require about a billion fewer keypresses in getting it set up (between web searches, gaining the requisite programming experience, writing your own keylogger for X11).  Also this would be much less prone to false positives.  Are you really never going to type the word "open" on your keyboard without wanting the programmed response?  You wouldn't have been able to type this forum post if you had such a tool running: it would have interrupted you as soon as you typed that word.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2016-09-27 18:14:37

1Try
Member
Registered: 2016-07-21
Posts: 16

Re: Application to bind commands to words

Hey Trilby smile,

Trilby wrote:

But getting an X11-wide keylogger that doesn't have horrible side effects is anything but trivial.

Trilby wrote:

This approach would require 2 extra key presses on every use.  But it would require about a billion fewer keypresses in getting it set up (between web searches

Trilby wrote:

Also this would be much less prone to false positives.  Are you really never going to type the word "open" on your keyboard without wanting the programmed response?  You wouldn't have been able to type this forum post if you had such a tool running: it would have interrupted you as soon as you typed that word.

All good points! Maybe you're right and I should try a new approach

Trilby wrote:

gaining the requisite programming experience, writing your own keylogger for X11

I'm not worried about the hard work since I'm doing all these things mainly because I enjoy it and I really want to gain experience. However, I want to do it in the right way and I think you highlighted every side effect.

So I could type <MENU>open<ENTER> and it would respond with whatever I configured it to do for the "open" command.

Basically I should add a new command and put it in one of the directories used by dmenu to find commands?

Offline

#7 2016-09-27 18:23:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: Application to bind commands to words

1Try wrote:

Basically I should add a new command and put it in one of the directories used by dmenu to find commands?

You could, but this would seem a bit wasteful.

First tinker with dmenu enough to learn the difference between dmenu and dmenu_run.  Dmenu does not look in any directories for anything, that's dmenu_run.

Dmenu_run is a tools which pops up a dmenu window, get's whatever the user types in it, then tries to run that input as a command.  You can use dmenu without using dmenu_run.  Write one single script that basically just does:
1) launches dmenu
2) captures what the user input in dmenu
3) does whatever you want with that input (maybe with a case statement)

This script is what could be bound to a menu command.

Or you could try out interrobang which can work like dmenu_run, but it allows you to define customizable actions for many "bang" keywords when the user input starts with a '!'.

So for interrobang I could type <Menu>!open<Enter> then interrobang would run whatever I defined for the "open" bang in the config file.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2016-09-28 22:32:17

1Try
Member
Registered: 2016-07-21
Posts: 16

Re: Application to bind commands to words

Sorry for not posting before! After reading your reply I immediately started working on my own script. I particularly fancied the idea of writing my own dmenu wrapper (as dmenu_run is called according to the wiki).
So thank you very much for your important advices. I'll soon post my very very very simple, and probably useless, script for the benefit of every arch noob like me smile

Offline

Board footer

Powered by FluxBB