AppleScript

Moom's AppleScript support lets you create, merge, and replace saved layouts, as well as generate a list of saved layouts and center windows.

If you used AppleScript in prior versions of Moom, you'll find the command set in the Moom Legacy Suite dictionary, so all your old scripts will still run. Our renaming of snapshots to layouts, though, required a new set of AppleScript commands, albeit with the same functionality as the old, plus one new command.

 

Commands

Run any Moom custom action

Note that custom action names must be unique, or Moom will simply run the first custom action with a matching name.

tell application "Moom"
  run "My Custom Action"
end tell

Center the frontmost window

Use one of the two forms below, depending on which screen center you want. This first version puts a window at macOS center, which is slightly above true center.

tell application "Moom"
  center frontmost window
end tell

And this version will center the frontmost window at true screen center.

tell application "Moom"
  center frontmost window geometrically
end tell

Return a list of saved layouts:

tell application "Moom"
  list of layouts
end tell

Activate a saved layout

tell application "Moom"
  apply layout "My Saved Layout"
-- alternatively:
-- run "My Saved Layout"
end tell

There's only one changeable value here: replace My Saved Layout with the name of the saved layout you'd like to activate.

If you have more than one saved layout with the same name, Moom will use the first saved layout when called via AppleScript. If you need access to the other saved layouts, you'll need to first give them unique names within Moom—simply appending a unique counter digit would work fine, for instance.

Merge new layout with existing layout

A merged layout will combine the windows in the saved layout with the presently-visible windows, writing the changes back to the existing layout. Note that the layout name is case sensitive, and if it doesn't exist, it will be created.

tell application "Moom"
  save layout and merge with "My Existing Layout"
end tell

Replace existing layout with new layout

Replace an existing saved layout with a new layout using the currently-visible windows. Note that the name is case sensitive, and if it doesn't exist, it will be created.

tell application "Moom"
  save layout and replace "My Existing Layout"
end tell

If you have additional Moom features that you'd like to have scriptable, please let us know by sending us an email.