Created
November 24, 2017 07:56
-
-
Save sdsykes/c55a9c745584b5d4124b7f881eecb8fe to your computer and use it in GitHub Desktop.
Balance desktops after unplugging or plugging in an external monitor using TotalSpaces2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'totalspaces2' | |
columns = TotalSpaces2.grid_columns | |
displays = TotalSpaces2.display_list() | |
if displays.size == 1 | |
spaces_count = TotalSpaces2.number_of_spaces | |
if spaces_count > columns && spaces_count % columns == columns - 1 | |
puts("Fixing missing space") | |
TotalSpaces2.add_desktops(1) | |
TotalSpaces2.move_space_to_position(spaces_count + 1, spaces_count - columns - 1) | |
end | |
elsif displays.size == 2 | |
spaces_count = TotalSpaces2.number_of_spaces | |
if spaces_count > columns && spaces_count % columns == 1 | |
puts("Removing extra space") | |
TotalSpaces2.remove_desktops(1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment