How to make a hotkey toggle

I have a macro that resizes the current window to make it as tall as possible. It’s useful when a web page or Terminal window isn’t tall enough to show some content. It works fine, but I’d like to hit the same hotkey a second time to return the window to the original size. I think the basic logic would be something like

if SavedWindowHeight == 0
    SavedWindowHeight = current window height
    set window height to the current screen height
  set window height to SavedWindowHeight
  SavedWindowHeight = 0

This might work as long as I always hit the hotkey twice while in the same window. It won’t work if I were to hit the hotkey, change windows, then hit the hotkey again. I guess I want a per-window variable, or a way to zero the variable whenever I change windows.

Is there an approach that might work?

Hey Pete,

I've done stuff like this in the past with AppleScript.

I'd use a text file OR a KM variable and a simple lookup-table syntax:

App-Name     Window-Name     Win-Pos     Win-Size

This macro shows how to gather that info on the front window.

Test » Window Pos, Size Lookup.kmmacros (2.4 KB)

So your macro would:

  1. Pull the info on the front window.

  2. Parse-out the app-name and window-name.

  3. Use regex to look in the table for an entry with same.

  4. If an entry is found then parse the entry for win-pos, win-size and
    use that to restore the window - then delete the entry.

  5. If an entry is NOT found then zoom window to the desired size and
    append the win-info to the file or variable.

This makes it pretty easy to store multiple windows from multiple apps in the same table.

A KM variable will be a little speedier than a text file.

That should at least get you started.

Best Regards,

Thanks! I’ll give that a try.