Remove Space from Mission Control

Hello, I have been using BTT for a couple of weeks and I love it. Moving left/right between spaces without those dreadfully slow macOS animations is honestly worth paying the 24 bucks for a lifetime license for me.

Another action I like is ‘Add New Space to Mission Control’. I use it a lot. However, I figured that there would be an action to remove a space but when I checked, there wasn’t. I am wondering if an action like ‘Remove Space from Mission Control’ to remove the workspace is possible to implement?

BTT has basically almost eliminated my need to use the mouse for Mission Control and this action would be the last thing needed to completely remove the mouse. To remove a space right now I have to: Three-finger swipe up, go to the space, hover over it and press the X.

I would be happy to help in any way I can.

Thanks!

Nevermind, I got a hacky solution similar to the one I implemented in this thread: Question about "Add New Space to Mission Control"

#!/usr/bin/env bash
# Create a new Desktop Space via Mission Control UI (no keystrokes).
# Requires: System Settings → Privacy & Security → Accessibility for your terminal (and launcher, if any).

osascript <<'APPLESCRIPT'
tell application "Mission Control" to launch
delay 0.25
tell application "System Events"
	tell list 1 of group 2 of group 1 of group 1 of process "Dock"
		set countSpaces to count of buttons
		if countSpaces is greater than 1 then
			perform action "AXRemoveDesktop" of button countSpaces
		end if
	end tell
	delay 0.6
	key code 53 --  # Esc key on US English Keyboard
end tell
APPLESCRIPT

save the script as: close_space.sh and give it execute permissions with

chmod o+rx close_space.sh

then map this command (with absolute path) to a keystroke in BTT and its done.

./close_space.sh

Here is a video of it in action:

1 Like

looks interesting, I'll check whether I can make this into a configurable action

1 Like

Thanks! Another piece of logic to consider is what Desktop to land on after closing the current Desktop.

The implementation I made does this:

D1, D2, D3, D4.
currently ---> ^ Close out current desktop (D4)

D1, D2, D3, D4.

^ Land on first desktop.

Ideally it should land on the previous desktop you were at before switching to 4 and closing. Like if you were at desktop 2 and then switched to desktop 4 and closed, then you should land on desktop 2.