0

I have recently switched to a keyboard with a particular layout, and I'd like to setup a system-wide keyboard shortcut to display an image overlay on the screen while pressed. This image would be a reminder of the keyboard setup.

I've found a few apps that allow for displaying an overlay over the screen, but I'm looking for something that can be toggled on and off at the press of a key.

  • which app did you find – Ruskes Sep 20 '18 at 20:19
  • @Buscar웃 I found a few on alternativeto.net/software/afloat – Alexandre Kirszenberg Sep 20 '18 at 20:50
  • ok, so now you want some kind of keyboard shortcut to turn it ON/OFF, do you know how to do that ? – Ruskes Sep 20 '18 at 20:55
  • No idea, and I'd like for it to be turned on on key press and turned off on key release. – Alexandre Kirszenberg Sep 20 '18 at 21:34
  • 1
    AppleScript can't detect keypress events in this manner. The only way to implement this with AppleScript would be to have it constantly running in the background, continuously testing whether or not a particular key has been pressed. This is a horrible drain on system resources and really bad scripting implementation. You'd be best advised using a third-party software solution like Keyboard Maestro which is very powerful and well worth the cost. Karibiner is a free, open-source alternative. – CJK Sep 21 '18 at 14:02
0

I ended up using Karabiner as suggested by CJK, with the following custom script which I placed under ~/.config/karabiner/assets/complex_modifications/custom.json. Just replace AppName with the name of your app and the "from" keybind to your preferred combination. The format is described here.

{
  "title": "Custom modifications",
  "rules": [
    {
      "description": "Toggle AppName visibility",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "f1",
            "modifiers": {
              "mandatory": ["shift", "control", "option", "command"]
            }
          },
          "to": [
            {
              "shell_command": "osascript -e 'tell application \"System Events\" to set visible of process \"AppName\" to true'"
            }
          ],
          "to_after_key_up": [
            {
              "shell_command": "osascript -e 'tell application \"System Events\" to set visible of process \"AppName\" to false'"
            }
          ]
        }
      ]
    }
  ]
}

Then, inside of Karabiner-Elements, in the "Complex Modifications" tab, click on the "Add rule" button, then enable your custom rule (in my case, the application I want to toggle is Helium).

Enabling the setting inside of Karabiner

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .