Skip to content

Instantly share code, notes, and snippets.

@sdsykes
Created November 24, 2017 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdsykes/c55a9c745584b5d4124b7f881eecb8fe to your computer and use it in GitHub Desktop.
Save sdsykes/c55a9c745584b5d4124b7f881eecb8fe to your computer and use it in GitHub Desktop.
Balance desktops after unplugging or plugging in an external monitor using TotalSpaces2
#!/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