DMBuce / macrobe

Companion scripts for xmacro

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Install

There’s an AUR package for Arch Linux and a Makefile for other distros.

You can also simply drop the scripts in your $PATH, make them executable, and make sure xmacro, perl, and bash 4.3+ are installed.

Configure

Running any macrobe command, e.g. macrobe --help, will create a default config for you if one does not exist at ~/.config/macrobe/config.ini . The default config has many comments to explain what each option does.

The [genmacro] section of the config has a mapping of characters to keysym sequences. To use genmacro to generate an xmacro script from text, or to play a dynamic macro with macrobe, these need to be adjusted to match your keyboard layout. You can use xev and press a key to see its keysym.

Users of i3 may want to uncomment the record_pre, play_pre, play_post, and loop_pre options in the default config, then add the following modes to i3’s config:

# record/loop modes
set $rmacromode (Esc) Stop Recording
set $lmacromode (Esc) Stop Macro
mode "$rmacromode" {
    # cancel
    bindsym Escape mode "default"
}
mode "$lmacromode" {
    # cancel
    bindsym Escape exec macrobe kill; mode "default"
}

In addition to displaying handy indicators when running macrobe record, macrobe loop and macrobe play, this setup lets you stop macrobe play or break out of macrobe loop using the Escape key, which will run macrobe kill.

Users who don’t have the above setup will need to find another way to launch macrobe kill when macrobe loop is running.

For users who want a simple GUI, here is an example config for blezz or rofi-blezz:

Macro:
act(r,Record, macrobe record)
act(e,Edit, urxvt -e macrobe edit)
act(p,Play, macrobe play)
act(l,Loop, macrobe loop)
act(c,Choose, sh -c 'macrobe `macrobe list | rofi -dmenu -i -p "Play Macro"`')
act(m,My Custom Macro, macrobe play my-custom-macro)
Blezz Menu

Usage

$ macrobe
Usage: macrobe list|kill
       macrobe record|edit|play|loop [macro]
       macrobe <macro>

Manage xmacro macros.

Temp Macros

Temp macros are files named tmp.* in ~/.config/macrobe/macros/. Several macrobe subcommands will use the most recent temp macro if no macro is specified on the command line.

Record a temp macro:

macrobe record

List all macros, including the most recent temp macro:

macrobe list

Edit the most recent temp macro with your $EDITOR (vi by default):

macrobe edit

Play the most recent temp macro:

macrobe play

Play the most recent temp macro on repeat:

macrobe loop

Kill all macrobe and xmacroplay processes:

macrobe kill

Named Macros

Rather than just manipulate the most recent temp macro, you can also record/edit/play/loop macros by name:

macrobe record my-custom-macro
macrobe edit my-custom-macro
macrobe play my-custom-macro # or macrobe my-custom-macro
macrobe loop my-custom-macro

Like all macros, named macros are stored in ~/.config/macrobe/macros, and like temp macros, they are simply xmacroplay scripts, so you can place them there yourself if you want. For example, to convert text from a file or command to a macro, you can use genmacro:

genmacro file.txt > ~/.config/macrobe/macros/my-custom-macro
somecommand | genmacro > ~/.config/macrobe/macros/my-custom-macro

Dynamic Macros

A dynamic macro is an executable file in ~/.config/macrobe/macros with a dot (.) in its name. When playing a dynamic macro, macrobe will run the executable, generate a macro from its output, and play the result.

To create a dynamic macro named foo, you can run the following. Note that the exact extension doesn’t matter, and you could use foo.py, foo.pl, or foo.bin instead, for example. If multiple foo.* files exist, macrobe uses the most recently modified one.

macrobe edit foo.sh
# save and quit, then
chmod +x ~/.config/macrobe/macros/foo.sh

Once created, you can edit the macro again without the extension

macrobe edit foo

If you play the dynamic macro with

macrobe play foo

macrobe will run the foo.sh script, process its output with genmacro, and run the result with xmacroplay.

Example

Suppose we want to create a macro that generates an out-of-office email. We want the macro to fill out the "To", "CC", "Subject", and "Body" sections of our email client. We can accomplish this by including tab characters in the macro, so that macrobe play will tab through those fields.

We also want it to prompt us for a start and end date with a tool like pickdate. Since these dates will change each time we generate the email, we will need to create a dynamic macro for this use case.

The script for such a macro might look something like this:

#!/bin/bash -e

# define some vars
mailto=$'department@example.com\tanother-dept@example.com'
cc='boss@example.com'

# schedule start date
start="$(pickdate -f '%A %-m/%-d')"
humanstart="$(date -d "$start" +'%a, %b %-e')"

# schedule end date
epochend="$(pickdate -f %s)"
end="$(date -d @$epochend +'%A %-m/%-d')"
humanend="$(date -d "$end" +'%a, %b %-e')"
humanback="$(date -d @$(($epochend + 24*3600)) +'%A')"

# print macro
cat <<EOF
$mailto			${cc}		Out of office $start thru $end	I will be out of the office from $humanstart to $humanend, returning $humanback.

Have a good one.
EOF

If I run this script with my cursor in the "To" field of my email client, I’m prompted for two dates and then xmacroplay fills out the email.

Of course, you will need to adjust the tabs in the script to be suitable for your email client, and other details as necessary for your use case.

About

Companion scripts for xmacro

License:GNU General Public License v3.0


Languages

Language:Shell 71.2%Language:Perl 16.4%Language:Makefile 12.4%