Hacker News new | ask | show | jobs
by throwamay1241 2502 days ago
For those looking for obscure-but-useful, checkout xdotool. `sleep 2; xdotool type "foo"` is super handy for typing passwords into virtual machines which don't support guest additions. I'd rather not elaborate on the filthy things I've made it do, but rest assured you can use it to do some quick and dirty automation tasks if you really need to :)
8 comments

On macOS I use Keyboard Maestro[1] with a "Type String" macro[2]. Pops up an input[3] and then types the string you enter after a delay. One of many time-saving uses for KM!

[1] https://www.keyboardmaestro.com/ [2] https://gist.github.com/chroder/a18178940cd1e96a76c4daea63dc... [3] https://i.imgur.com/UEjDfNJ.png

Autokey (Python) gives you similar power as AutoHotKey on Windows and Karabiner Elements/Hammerspoon on macOS.

Problem is, that you might want Wayland support, as X is on the way out.

[1] https://github.com/autokey/autokey

> Problem is, that you might want Wayland support, as X is on the way out.

I vaguely remember someone saying something similar about IPv6 once.

Last time I tried Karabiner Elements, it was quite buggy and brought down the kernel. Not a happy camper. Then Apple blessed us with allowing Escape-Caps remapping out of the box (guess that Touch Bar resulted in something useful...)

Did it improve? What do you remap?

FWIW, it does not crash (for) me.

I mainly use Hammerspoon as I prefer Lua over Json. I find Lua far easier to modify... to be fair, both Hammerspoon and Karabiner Elements have quite an impressive repository. If you want to do something it is probably already done.

My favourite is probably swapping of Cmd to Ctrl in VMs. That way you can use keybinds in Linux or Windows VM with the same muscle memory as in macOS. It may get confusing if you use Super a lot in Windows/Linux.

Another one is rebinding right Option (or "Alt") to Hyper. Most of the keybinds I use I got from this repo [1]. Though I did make quite some modifications I found it a good starting point (merging my own back). I remap Caps to Escape and Ctrl (latter if combined with another key) via Hammerspoon. You could also use Karabiner Elements though. Although I still use Caps mainly for Esc (muscle memory...)

On a Windows computer, I used AutoHotKey for some other stuff (gaming related QoL improvements). For some reason, Blizzard decided that in WoW you are not allowed to spam a key if you hold it. Which is flat out painful for the hands. I no longer play WoW regularly though. If I do, it is via Wine (on a Linux desktop). In Diablo 3 I made a keybind to swap gearsets. This was before Blizzard implemented the wardrobe.

[1] https://github.com/jasonrudolph/keyboard

I've started using it a few months ago, and it seems pretty stable.

I've got a fancier mapping for the caps lock key: when you hold it, it works like ctrl, and when you tap it it works like escape.

I've also got something similar for space: when I tap space, it works like space. When I hold space, I can tap additional characters. (So space works like a modifier, similar to ctrl or shift.) For example, space-x = delete, space-p = page up, space-j = cursor down.

I'm using the same keybind as you do.

The space one however, did not work well for me. It resulted too frequently in space not working at all. Supposedly it got matched as a combination with another key instead of a tap.

I recommend to apply a new rule, then test it out, then make another change. This way, you figure out which rule poses an issue.

There is one ruleset in Hammerspoon in the Github repo which I mentioned which -for me- makes it impossible to type cd. It always becomes c d

One of the three major reasons why I use Mac OS rather than Linux is the existence of Keyboard Maestro and TextExpander, which do tons of useful things and work everywhere. (if you care, the second reason is working system-wide clipboard and the third reason is Emacs keybindings in ALL dialog boxes and inputs).
I really like mac keybindings.

However, I really dislike how if I click what is traditionally the maximize button, it doesn't maximize both horizontally and vertically. I also really dislike how if I use the fullscreen mode and then use alt tab to switch windows it takes like 400ms to transition with some animation, and I can't disable it. I also really dislike how alt tab behaves, I want it to switch all windows not window classes. I also really dislike that I can't alt-click+drag to resize or move windows like I can in linux.

But most of all, I really dislike that there's no easy way to modify these behaviors without installing third party applications which at best can be described as dirty hacks.

They're the major reasons I use GNU/Linux over MacOS. Or would choose Windows over MacOS if Linux wasn't available.

> However, I really dislike how if I click what is traditionally the maximize button

That's no keybind though. The keybind for fullscreen is Control-Command-F as per [1]. On Firefox, I use Tree Tab Style and in order to hide the tabs, I need to also hide the top bar with the 3 top left window management symbols. Forced me to learn the shortcut (Cmd+H is another one I regularly use, to hide current application).

We should assume the user also is able to utilize multitouch gestures on TrackPad.

Fullscreen applications work very well with 3 finger swipe up which yields all windows and desktops, or 3 finger swipe down which allows further interaction to select the top window. Triple swipe left and right switch to current desktop minus or plus one. If you're going to run a VM, you will need these gestures.

Nothing in Linux land beats these gestures nor the Apple Magic Trackpads, IMO. I've been trying to get my Apple Magic TrackPad 2 to work on Linux. With multitouch. It works, but not as good as on macOS (tried with Libinput 1.13, not 1.14 yet).

You can use Cmd+` to swap between application windows. Nice boss key.

I found two third party apps which potentially fix your issue: Witch and HyperSwitch.

> and then use alt tab to switch windows it takes like 400ms to transition with some animation, and I can't disable it.

I didn't find a way to fix this. It does not bother me, as it is easy on the eyes, but I understand your concern. I also agree it is annoying that we need third party applications to fix these use cases but it does go with the minimalism theme. You could regard Gnome Tweaks as the same problem. And there's more third party applications I wouldn't want to live without such as Bartender.

> I also really dislike that I can't alt-click+drag to resize or move windows like I can in linux.

For resizing or dragging you can do this with the titlebar. I'd use one of these third-party applications like Spectacle or Amethyst to manage windows. I agree its a loss this isn't native. (I suppose Hyperdock provides this functionality?)

[1] https://support.apple.com/en-us/HT201236

If you're doomed to use Windows, you could use AutoHotKey (if allowed to).

It is FOSS, the scripting language is simple (though not Python, like AutoKey, there is an old Python port of it), and there is a large community with decent documentation and examples available.

AutoHotKey, unfortunately, does not work on Linux, at all. Not even with Wine.

I love that the keybinds on macOS are rather universal.

PLEASE elaborate on the filthy things you've made it do!
- Unit/Integration test X11 tools inside docker Xephyr sessions during CI

- Transplant magnet links from ThePirateBay into a bittorrent client

- Type stuff into virtual machines rather than install guest additions

- Import data into remote desktop sessions for otherwise internet-isolated+Copypaste disabled remote hosts, complete with integrity checking powershell scripts which were also imported into the environment that were used to self-integrity check prior to integrity checking other files.

The use of xdotool is probably an antipattern in a perfect world, but that doesn't mean that it's not damn handy from time to time.

One of the less awful things I've done with xdotool is to hook into latexmk to continuously update the window title of the resulting PDF with the compilation status. So you can have the screen split just between editor and pdf viewer, with the compile always running in the background, yet know what the status is. This got upstreamed into latexmk some years back.
I use it for all sorts of things.

I recently had to do some mandatory training which would require me to spend 30h in front of the computer clicking every couple of seconds. The issue is that I already know the material perfectly well, so my time would be spent better learning something else.

Nothing so difficult that couldn't be done with simple shell loop and automated clicking with xdotool:)

I suggest Sikuli, it does fuzzy matching on your screen contents to determine whether to continue with your dirty, dirty hacks.
For a lighter-weight alternative to Sikuli that does not require Java, check out visgrep[1] from the xautomation project.[2]

[1] - https://linux.die.net/man/1/visgrep

[2] - https://hoopajoo.net/projects/xautomation.html

For a new light-weight alternative to Sikuli that does not require Java, check out the UI.Vision browser extension + xmodule:

https://ui.vision/x/desktop-automation

I rememberdemoing Sikuli to the boss, when it clicked where we didn't expected just because the web we were trying to automate had a link we didn't notice.
... or cheat cookie-clicker.
xdotool is the dirty magic underlying my personal voice-control system for Linux. Super-useful for being able to arbitrarily interface with X, without having to learn the insane interface you're supposed to use.