Created
April 9, 2024 04:36
-
-
Save olivierroy/da9bb86b4b0510c15c8fe54a4715084f to your computer and use it in GitHub Desktop.
Save and restore workspace positions in linux
This file contains 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 | |
# 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