Using Moom with Bunch for window management

One of the feature requests I get now and then for Bunch is to allow it to arrange windows. Some other batch launchers have this feature, but they usually have a GUI, and making that kind of thing work with plain text files is an ugly proposition. There is a good option, though.


This is a companion discussion topic for the original entry at https://brettterpstra.com/2020/09/14/using-moom-with-bunch-for-window-management

Can anyone tell me if Moom can manage Desktop/spaces?

Desktops yes, Spaces no. I’ve never seen an app that can control Spaces.

It is possible to Use Bunch and Moom to control windows in multiple desktops/spaces (note that Apple uses both terms to refer to the same thing as different places).

The key point is to have Bunch move to the space/desktop you want the applications, files, and folders to be on, then open them, then have Moom arrange the windows. And then repeat for the next space/desktop. It will take some experimenting with delays in Bunch.

There are two ways to have an application open in a specific space (which you may already know).

  1. When an application is running, navigate to the space you want the application on, right click on the Dock icon, and in the menu select Options > Assign to This Desktop. And now when this application launches it will be placed on the specified desktop.

  2. In Bunch you can specify the space to open on but it requires some set up.

  • In System Settings > Keyboard > Keyboard navigation - Keyboard Shortcuts (button) > Mission Control > Mission Control (checkbox) – enable the “Switch to Desktop N” keyboard shortcuts for the N spaces/desktops you use.

  • In Bunch use the syntax {^N}, where N is the space/desktop to switch to. Then list the items to open on that space. Then trigger Moom to rearrange that space. Then move to the next space. You’ll need to experiment with the delays in Bunch to make things work.

Note that if you use method 1, then launching such an application in Bunch will switch to that space, and you can sequence the other apps for that space after this one, again experimenting with delays in Bunch.

I use these techniques in my set up, which has four monitors and ten spaces.

1 Like

Shouldn’t - {^7} tell Bunch to open apps in desktop 7? Then the Moom AppleScript will arrange the windows of the open apps?

I’ve setup desktop shortcuts

Here is how my Bunch file looks:

- {^7}
Numi.app ~4
Skype.app ~4
* tell application "Moom" to arrange windows according to snapshot "Space7"

Also, this is just an example, I know Skype should never be on a system in 2024.

Using the “- {^N}” syntax sends the keystrokes to the preceding application.

However, since ^N is a global hotkey combination, you can remove the “-” and just use {^N}.

Reference: Keystrokes - Bunch.app

I tried it both ways and I still got this message from Moom:

CleanShot 2024-02-02 at 11.56.43

Because Bunch wants to open everything in the current desktop. These commands: - {^7} nor {^7} didn’t register with it.

Here is a simple example that works just fine for me.

---
title: Test Bunch
---
# Test Bed for Bunch Ideas

{^7}
PCalc

* tell application "Moom" to arrange windows according to snapshot "Bunch Test" ~2

{^1} ~5
CotEditor ~10

* tell application "Moom" to arrange windows according to snapshot "Bunch Test Two" ~20


* say "good morning Steve"

Note the delays. I had to experiment a bit to get it to work.

The possible issue here is that Moom is being invoked before the applications are launched. Put a delay on this line so that it happens after the last of the applications is launched.

I tried until I couldn’t try anymore.

The Moving into numbered space just wasn’t consistent with bunch or moom. The apps either opened in the last space or stated in the original space where the bunch was launched from.

Here is a screenshot of my last attempt both apps ended up on top of each other on Desktop1.

---
title: Test Bunch
toggles: false
---
# Test Bed for Bad Bunch Ideas
 
{^7}
- (pause 5)
Numi.app ~5

* tell application "Moom" to arrange windows according to snapshot "Space7" ~30

{^8} ~2
- (pause 5)
Skype.app ~5

* tell application "Moom" to arrange windows according to snapshot "Space8" ~30


* say "good morning A.B."

The name script was the one thing that always worked.

Hmm …

Are the keyboard shortcuts to move to different spaces working from the Finder? If yes, then the issue is with the bunch file. If not, then that is where the problem lies.

With respect to the Bunch file, it is not clear why the “pause” is needed after moving to either space. Nor why you are pausing the open of Numi.

If you are still interesting in troubleshooting, try building the bunch file up one line at a time. Of course you may have already tried this. But it not, comment everything out except the {^7} line, run the bunch, and see if focus switcheds to space 7. If yes, then add the “Numi.app” line without the 5 second delay, and watch how long it takes Numi to launch (if Numi launches before the switch, then add a delay to Numi). If this works then add back the Moom line, with a delay slightly longer than it takes Numi to launch.

Continuing, the add back the {^8} line with a delay long enough to allow all of the prior steps to complete. That is, don’t switch to space 8 until after Moom has arranged the windows. Continue to add back lines adjusting the delays so that each subsequent step happens after all the prior steps have completed.

If you look at my sample Bunch, each delay is larger than the prior delay.


Other things you can check.

  • Are either Numi or Skype set to open on a specific space? Right click on the icon in the dock and check under the Options submenu. If so, they will shift focus to that space when opening.

  • Are either Numi or Skype already open when you run the Bunch? (I ask because you have “toggles: false”.)

  • In System Settings > Desktop & Dock > Mission Control, is the “Automatically arrange Spaces based on most recent use” set to on? (This one is just a guess.)

I hope this helps. And let us know how you make out.

One thing to check would be whether you have your Bunches executing in parallel or sequentially. You can force this for any given Bunch by including the followin in frontmatter:

sequence: sequential

That would make sure that everything was launching in order and the delays were actually affecting the next open application. The implementation isn’t perfect, but sequential execution would be far preferable for a Bunch like this.

Also curious if you’re intending to use both ~X and - (pause X) at the same time. The ~X delays could just be increased to avoid the - (pause) commands in these cases.

Not that any of that will necessarily solve your issue, Spaces are very difficult to work with in general.

1 Like

I changed my test Buch to match yours:

---
title: Test Bunch
---
# Test Bed for Bunch Ideas

{^7}
- (pause 5)
PCalc ~5

* tell application "Moom" to arrange windows according to snapshot "Bunch Test" ~30

{^8} ~2
- (pause 5)
CotEditor ~5

* tell application "Moom" to arrange windows according to snapshot "Bunch Test Two" ~30


* say "good morning Steve"

And obtained the following results.

  • The {^7} and {^8} were seemingly ignored as focus did not change.
  • The ‘good morning’ command was executed.
  • PCalc and CotEditor both opened on the same space (the space the bunch was run from).
  • Both Moom commands were executed.

Removing both pause commands gave the following results:

  • Focus was shifted to space 7.
  • The ‘good morning’ command was executed.
  • Focus was shifted to space 8.
  • Both PCalc and CotEditor were opened on space 8.
  • Both Moom commands were executed.

As far as I can tell this is what is happening, in the ‘no pauses version’.

  • Focus shifts to space 7 as it is first and has no delay.
  • The ‘good morning’ command executes next as it has no delay.
  • After a 2 second delay focus shifts to space 8.
  • After a 5 second delay both PCalc and CotEditor launch.
  • After a 30 second delay both Moom commands are executed.

Also note that Moom cannot reach across spaces. So it only ‘sees’ windows in the space that has focus. Thus having both Moom commands on a 30 second delay means that they will both execute on whichever space as focus after the 30 second delay. To make it work as you want, you’ll need to ensure that the appropriate Moom command executes while the desired space still has focus.

No, Skype and Numi are off and “Rearrange spaces based on most recent use” is off as well.

mission control

I thought I tried this as well, but I’ll try it again and report back.

I added sequence: sequential but it seemed “to me” that it did the last line first. Both apps ended up on space 7.

---
title: Test Bunch
toggles: false
sequence: sequential
---
# Test Bed for Bunch Ideas
{^7}
Numi.app ~5

* tell application "Moom" to arrange windows according to snapshot "Space7" ~15

{^8} ~20
Skype.app ~5

* tell application "Moom" to arrange windows according to snapshot "Space8" ~35

* say "good morning A.B."

You are telling both apps to open after a 5 second delay, Thus Skype is launched well before the command to switch to space 8.

Change this line, “Skype.app ~5” to “Skype.app ~25”.

1 Like

I removed Skype and it seemed to work. I’ll try your suggestion as well.

Success! I finally got it to work.

---
title: Test Bunch
toggles: false
sequence: sequential
---
# Test Bed for Bunch Ideas
{^7}
Numi.app ~5

* tell application "Moom" to arrange windows according to snapshot "Space7" ~20

{^8} ~45
Skype.app ~50

* tell application "Moom" to arrange windows according to snapshot "Space8" ~60

* say "good morning A.B." ~75

2 Likes