# Tutorial - Personalized typing macros with gtkmenuplus
## Overview
In this tutorial you will learn how to create, use and update your own menu of typing macros.
A typing macro is a combination of keypresses that can be repeated at will by selecting its label in a menu.
Gtkdialog draws the menu and executes the macro via one of the supported tools.
You invoke the menu from the command line or an icon or, preferably, from a system hotkey.
You create the menu entries using the simple template attached to this tutorial.
When the macro is executed its text content is inserted at the text cursor position in the active window.
## Prerequisites - What you will need
* GTK+ 2 (*)
* Gtkmenuplus[:1] for your distribution
* xdotool[:2]
* Optional: some way to assign a global hotkey to invoke the menu.
(*) For GTK+ 3 you can download gtkmenuplus source files and compile with GTK+ 3 as a dependency.
You need to install gtkmenuplus and xdotool in your system, and confirm they work correctly.
For Fatdog64 users
Gtkmenuplus is already included in the base system.
Xdotool can be installed from Gslapt Package Manager.
Optional: Sven Multimedia Keyboard daemon runs in the icon tray and provides global hotkey assignment. Instructions for Sven are given at the end of this tutorial.
For Puppy Linux users
Gtkmenuplus pets are attached to the first post in this thread.
Look for xdotool in your package manager.
Optional: There are many ways to assign a global hotkey but I can't be specific. Feel free to add your instructions for your favorite method to this thread.
For The Dogs users
I'm not sure if fredx181 has gtkmenuplus in his repos. If not, you should be able to extract the ".txz" archive attached to the first post under "/". You only need the "usr" folder, leave "install" out.
Xdotool should be in the repo, if not already in the base *Dog system.
Optional: I don't know much about defining global hotkeys in The Dogs. One way is through the Openbox configuration file.
## The template file
The attached template is a gtkmenuplus definition file with string ".tar.gz" appended to befriend the forum software.
Download the template file, save it to a directory somewhere in your $PATH, rename it to remove the trailing ".tar.gz", and make it executable.
You will edit this file to add your own typing macros.
As is the template includes just one macro named "edit this menu".
## First run
Start the template file, either by clicking its icon in the file manager or by typing its name in a terminal window or by pressing its associated hotkey (if you did associate a hotkey to the menu).
Select "edit this menu": your default editor (defaulttexteditor) will open the template file. Write your changes, save the file, quit the editor.
## All runs
When you need to add a new text item or modify an existing one follow the steps listed for the first run.
When you need to use a text item, start the template file with the text cursor positioned in the
active window where the text should appear, and select the item label. If you change your mind, press the Escape key or click anywhere outside the menu to dismiss it.
Note that a global hotkey is the only practical way to start the template file to target a graphical window, such as Geany's.
## What items can be added
Essentially, for each text item you need to write "item=" (no quotes) followed by the item label, and "cmd=" followed by either "$TYPE" (no quotes) and the text to be typed or a command that outputs such text. See the examples below. Optionally, you can add a tooltip, format the menu with larger fonts, colors, icons, predefine variables, conditionals, and so on -- all of which is beyond the scope of this tutorial but you can read the fine manual[:3].
If an item label includes an underscore, the character following the underscore can be pressed to quickly select that label. If no other item could be selected by that same letter the selection will also be executed immediately.
### Examples
Item= and cmd= are required. $TYPE invokes xdotool.
Your e-mail address
Code: Select all
item=me@example.com
cmd=$TYPE me@example.com
Quoting
Code: Select all
item=spaces and quotes
cmd=$TYPE "Is the last word in \"quotes\"?"
Submenu
Code: Select all
submenu=My submenu
item=One
cmd=$TYPE One
item=Two
cmd=$TYPE Two
endsubmenu
Divider
Current date formatted as YYYYMMDD
$DATETIME expands to, e.g., "20200418 235959".
Code: Select all
item=yyyymmdd
cmd=sh -c 'set -- $DATETIME; $TYPE "${1//[-:]}"'
tooltip=$DATETIME
Current time formatted as HHMMSS
Code: Select all
item=hhmmss
cmd=sh -c 'set -- $DATETIME; $TYPE "${2//[-:]}"'
tooltip=$DATETIME
Press enter
$PRESS_ENTER types the Return (Enter) key.
Target a terminal window to see the immediate execution of the echo command.
This works in rox filer's command prompt, too.
Code: Select all
item=hello world
cmd=sh -c "$TYPE echo 'hello world' && $PRESS_ENTER"
## Troubleshooting
Invalid gtkmenuplus item syntax aside (user error), each keyboard is a little bit different from all others, especially as regards key modifiers (Ctrl, Alt, etc.) and key timing. Xdotool allows modifying the timing between keypresses (default 12 ms) with the "--delay <milliseconds>" option. To apply a custom timing modify the definition of $TYPE near the top of the template file.
## Links
[:1] gtkmenuplus
*
https://github.com/step-/gtkmenuplus
*
http://www.murga-linux.com/puppy/viewtopic.php?t=107982
[:2] xdotool
*
http://www.semicomplete.com/projects/xdotool/
*
https://github.com/jordansissel/xdotool/
[:3] gtkmenuplus configuration directives
*
https://github.com/step-/gtkmenuplus/bl ... _format.md
## Hotkey with Sven Multimedia Keyboard Daemon (Fatdog64 Linux)
Since I use Sven I'm going to describe how to associate a global hotkey for the template file with Sven.
These instructions assume that key Windows+q isn't already assigned as a hotkey.
If it is assigned, you need to disable the assignment in Sven's configuration before re-assigning it.
* Right-click the keyboard icon -- located in the desktop panel icon tray --to open Sven's menu, and select Preferences.
* Click Keyboard > New > Description and type "Typing macros Win+q" without quotes.
* Click inside input field Key Code with your mouse, then press keys "Windows" and "q" together, don't press other keys.
* Click inside input field Text Display with your mouse, then type "Win+Q typing macros".
* Click the Program radio button, and type: /<path-where-you-put>/keyboard-macros.gtkmenuplus
(Change path "<path-where-you-put>/" according to the actual location of keyboard-macros.gtkmenuplus).
* Click OK and close Sven.
Press Win+q to test the global hotkey.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]