a blog of ideas and improvements for tormach cnc mills
articles | for sale | about | contact




if [[ "$(xdotool getactivewindow getwindowname)" == *'tormach'* ]]; then

xdotool sleep .1
xdotool mousemove 70 440
xdotool click 1
xdotool mousemove 70 400
xdotool click 1
xdotool sleep .1

xdotool type "G20"
xdotool key Return


Here are some examples.

Sets G20 | Sets G54 | Sets the Feed Slider to 20% | Goes to X0

Here's all of them





You will install xdotool and write bash scripts that command mousemoves, mouseclicks and key presses to tell your machine to do whatever you want. Then, bind those bash scripts to hotkeys via the built-in app Keyboard Shortcuts. This gives you, for instance, CTRL+SHIFT+X to probe a rectangular boss.

Finally, and optionally, bind third party USB macro boards to those shortcuts. So CTRL+SHIFT+X becomes one individual button on those macro boards.

This gives you one-button Cycle Start, Probing, any M command, any G command. Anything.

  • 1. Install xdotool.
  • 2. Write xdotool scripts.
  • 3. Bind xdotool script to key combo (CTRL+ALT+G).
  • 4. Optional. Buy macro keyboard to bind individual keys to key combos (that three button CTRL+ALT+G becomes one button).



Useless prelude:

I am a sucker for efficiency. I'm always trying to squeeze that last microsecond out of some procedure. This isn't even restricted to the CNC machine. Or computers in general. If I can shave time off of something (often at the expense of cosmetics), I'm doing it. On Windows machines, I have dozens of autohotkey scripts written. On Linux, it's xdotool.

With that, comes a general hatred for mice and touchscreens. Especially coolant-resistant touchscreens that are a pain in the butt to press.

I'll go head to head against anyone. I'm faster on a well laid-out keyboard than anyone with a mouse, keyboard and touchscreen combo. CAD, CAM, programming, web development. The speed is in the keyboard.

So it stands to reason that vanilla Pathpilot makes my head spin. Tormach has a few hotkeys built in, but not nearly enough. Their new operator console is a step in the right direction, but there should be a shortcut for everything. And you shouldn't have to spend $2000.

Well, there is now.

  • One-button cycle start? Done.
  • One-button probing? Done.
  • One-button axis moves in any (or all axis') direction? Easy.
  • One-button spindle speed changes? You spin me right 'round, baby, right 'round.
  • One button G54, G55, G20, G21, G30, G- and M-whatever? YES SIR.
  • One button shutdown? One button spindle warmup? One button gcode editor? Done and done and freaking done!

CNC machines are the pinnacle of efficiency. So let's make the software just as fast.

STEP 1 - INSTALL xdotool

  The star of the show is an app called xdotool.

The very first step is installing it. Do so by opening a terminal window. From Pathpilot, that's typically CTRL+ALT+X, though it may be different for you.

Type mate-panel to get into the Linux GUI. This may be different for you (gnome-panel for instance).

Then bring up a second terminal window by going to the Start button (Menu button in Linux) and typing terminal.

Then, just type:

sudo apt-get install xdotool

xdotool is going to allow you to move the mouse, click the mouse and type keyboard letters from simple plaintext scripts that you can write.

Here's my G20 script example. This sets your machine to G20 (Imperial units).

#!/bin/bash                     # every script must start with this line, called a shebang

xdotool sleep .1                # xdotool is typically "too fast" for Pathpilot, so you slow each command down by a tenth of a second
xdotool mousemove 70 440        # moves your mouse to the main tab icon (so if you're in Conversational, this moves to Main)
xdotool click 1                 # clicks the main tab
xdotool mousemove 70 400        # moves up to the MDI line (that's 70 pixels on X, 400 on Y)
xdotool click 1                 # clicks the MDI line
xdotool sleep .1                # sleep gentle baby sleep

xdotool type "G20"              # literally types G20
xdotool key Return              # presses enter

In this example, every line is commented for clarity. Real world scripts CANNOT have the first line commented. The top line MUST read:



  You can literally copy that script, save it to a file and make it do its thing.

Save it into your /gcode folder. Do that via Dropbox, thumb drive, wifi, however you transfer your files.

Note that Linux scripts don't like when they're edited on Windows machines. So you may be better off downloading them from my site, then editing them directly on your controller. Or, writing them from scratch on your controller in gedit.

If you do want to edit them on Windows machines, install dos2unix on your Linux machine and from a terminal window type "dos2unix g20.sh" (no quotes).  You may not HAVE to do this, but you probably will.

Another option is to open the files in gedit on your controller, then going to File | Save As and in the bottom right, find Line Endings and selecting Unix / Linux

Again, the top line can't be commented. The top line must read exactly like this:


For organization, you should save them into something like /gcode/shortcuts/ with the filename g20.sh.

If you haven't already, fire up your Windows-esque GUI by typing mate-panel back in your terminal window. This may be gnome-panel or something else depending on which version of Linux was shipped to you.

You should get a Windows-style Start menu at the bottom. Click that and find Keyboard Shortcuts.

Click Add near the bottom right and type in the following:

Name: G20

Command: bash "gcode/shortcuts/g20.sh" (exactly like that, with quotes)

Click Apply, then assign it whatever key combo you want. Try CTRL+ALT+G

Now, you can more or less be done here, if you want. Pressing CTRL+ALT+G on your keyboard should set G20 for you.

The next step is the real money, though: Binding it to ONE key.


  Here's where it gets slightly annoying.

When I was fleshing out this idea, I learned that there are a few brands of macro keyboards available. Each with their strengths and weaknesses. If you go down this road, you should be aware of all of them.

In my photos, you see two styles of macro boards. Two Penclic on the left, two Teenii on the right. And, for a short time I had a Koolertron model.



  • The biggest advantage to the Penclic is that it is the most professionally made of the bunch (in hardware at least). They're Swedish and you'd believe it. They're well made with soft button presses. They, by far, look the nicest.
  • They are also the lightest, slimmest and sleekest.
  • Doesn't require xdotool or screwing around in Linux AT ALL. You can do all the work in Penclic's software, on a Windows machine, then just plug it into your controller.
  • The second big advantage, only really applicable if you have dozens of shortcuts written, is that their proprietary software skirts around the issue that you can literally run out of key combos to assign.
  • I have dozens of shortcuts written. I've used up all my CTRL+SHIFT+ (A through Z), CTRL+ALT+ (A through Z). You only get around 75 combos before you start running into compatibility issues. I doubt anyone reading this will ever have as many shortcuts as me, BUT IF YOU DO, the Penclic boards will be your saving grace.
  • How? You can either assign the Penclic buttons to combos (CTRL+ALT+G) or bake the mouse movements right into it. Their proprietary software allows recording mouse movements, key clicks, etc. Easiest way to think of it is, is that they have their own version of xdotool built in.
  • If you're a sadist, and use their proprietary software to write the scripts, then you don't need xdotool and you don't need any key combinations at all. This was actually how I initially started, when I first bought the Tormach. I wrote the scripts with Penclic's software and just plugged the Penclic into the controller. That's it, it just worked.
  • But, all that glitters is not gold, because:


  • The big disadvantage is that their proprietary software, which you have to use, sucks. And it sucks big time.
  • For as well made as the hardware is, it's astonishing how poorly written the software is.
  • Can you get it to work? Yes.
  • Will it crash on you constantly? Yes.
  • The good news is, after you have it set up, you never have to touch it again. It's not even hard to use and there's no learning curve. It's just buggy and crashes often.



  • The Teenii's are my favorite. If I didn't already have my Penclics set up, and if I wasn't plum out of available combinations, I'd use nothing but Teenii.
  • The Teenii's are professionally made, with mechanical key clicks. They're noisy, providing a definitive sound and feedback. You may, or may not, want that, and it's in direct contrast to Penclic's soft clicks.
  • The software is well written and "just works". You load it once, assign each key on the Teenii to a combination (like CTRL+ALT+G) and you're done. You never use it again.
  • They're also wireless, though I don't recommend using them that way.


  • They're the biggest of the bunch, by far, especially considering the number of keys you're given.
  • The layout is silly, with lots of dead space.
  • One of the keys can't be assigned. It's top-center. It's the wired/wireless selection key.
  • You can technically run out of available key combinations, both in Teenii's software and in Linux.



  • Has the most keys-per-inch. Of the three boards I've used, it's the densest, allowing you to cram the most keys in the smallest amount of space.
  • Software just worked, if I recall correctly, but I didn't keep them around long enough to really bother.


  • Sloppily built. The base looks 3D printed (and probably was) and I swear it had three different batches of key caps installed on them. None of them matched.
  • Koolertron appears to be a large company with dozens of products. But, these things look like they were made in someone's basement using parts from Aliexpress.
  • You can technically run out of available key combinations, both in Koolertron's software and in Linux.
  No matter which board(s) you buy, all you're doing is using their proprietary software and assigning their keys to combinations (So, the "1" on whatever board becomes CTRL+ALT+G, etc).

The exception to this is that you can write your own script on a Penclic board, if you choose to. But, you can also just assign a Penclic key to a combination. Either way.

After that, just plug them into your controller. They're automatically found, installed and ready to work.

  All this is for naught if you don't know how to write xdotool scripts.

Fortunately, it's pretty simple. Plus, I've uploaded all my scripts for inspection and dissection.

xdotool is powerful, but we really only need around five commands to use it with Pathpilot.

mousemove to literally move the mouse somewhere on the screen.
click 1 to left click (click 2 to middle click, click 3 to right click)
type to literally type (like on the MDI line)
key to press special keys (like Return, Insert, Page Down)
sleep to slow the script down (it will move faster than the computer)
getmouselocation to figure out where on your screen an area you want to click is actually located.

From a terminal window, type xdotool getmouselocation BUT DON'T PRESS ENTER YET.

Leaving it open, move and hover your mouse back to where you need it. You can ALT+TAB back into Pathpilot if necessary.

When you have the mouse where you want it (MDI Line, Probe Button, whatever), switch back to the terminal window and press enter. xdotool will spit out the location, which you can then use in your script.

You should also add this if statement to every script you create, which prevents them from running unless Pathpilot is the active window.


if [[ "$(xdotool getactivewindow getwindowname)" == *'tormach'* ]]; then

xdotool sleep .1
xdotool mousemove 70 440
xdotool click 1
xdotool mousemove 70 400
xdotool click 1
xdotool sleep .1

xdotool type "G20"
xdotool key Return


IF starts the if statement and FI ends it. So, your code goes between the IF and the FI.

I have some advanced scripts that run some weird stuff, that would probably be pretty dangerous if run in Pathpilot (and some if ran outside of Pathpilot).


  • 2024-03-29 = Added code showing how to move the Feed, RPM and Velocity sliders with a one-key shortcut.