Skip to content

Instantly share code, notes, and snippets.

@olivierroy
Created April 9, 2024 04:36
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 olivierroy/da9bb86b4b0510c15c8fe54a4715084f to your computer and use it in GitHub Desktop.
Save olivierroy/da9bb86b4b0510c15c8fe54a4715084f to your computer and use it in GitHub Desktop.
Save and restore workspace positions in linux
#!/usr/bin/env ruby
# Usage:
# cmd: move-windows.rb save
# to save current windows workspaces to a move-windows.save file
# cmd: move-windows.rb
# to adjust windows workspaces according to the positions in the saved file
location = File.dirname(__FILE__)
save_filepath = "#{location}/move-windows.save"
if ARGV[0]=="save"
windows = `wmctrl -l`
File.write(save_filepath, windows)
else
window_postions = `wmctrl -l`
saved_window_postions = File.read(save_filepath)
positions = {}
saved_window_postions.split("\n").each do |window_line|
window_id = window_line.split(" ").first
desktop_id = window_line.squeeze(" ").split(" ")[1]
window_name = window_line.split(" ")[3..-1].join(" ")
positions[window_name] ||= []
positions[window_name] << desktop_id
end
window_postions.split("\n").each do |window_line|
window_id = window_line.split(" ").first
window_name = window_line.split(" ")[3..-1].join(" ")
desktop_id = window_line.squeeze(" ").split(" ")[1]
saved_desktop_ids = positions[window_name]
if saved_desktop_ids && saved_desktop_ids.length==1
saved_desktop_id = saved_desktop_ids.first
if saved_desktop_id != desktop_id
`wmctrl -ir #{window_id} -t #{saved_desktop_id}`
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment