Use Alfred + TotalSpaces move windows to current space

require ‘totalspaces2’
def alfred_move_windows(appname)
current_space = TotalSpaces2.current_space
windowsall = TotalSpaces2.window_list
if !windowsall.empty?
no_current_windows = windowsall.select {
|window| (window[:space_number] != current_space)&&window[:app_name].downcase =~/#{appname}/
}
end
no_current_windows.each{|window|
win_pra = (window[:frame].delete"{} ").split(’,’)
xpos = win_pra[0].to_i
ypos = win_pra[1].to_i
width = win_pra[2].to_i
off = 1920 - xpos
if window[:space_number] < current_space
TotalSpaces2.move_window(
window[:window_id],-1920, ypos)
TotalSpaces2.move_window_to_space(
window[:window_id], current_space)
TotalSpaces2.set_front_window(no_current_windows[0][:window_id])
0.step(1920,5){|n| TotalSpaces2.move_window(
window[:window_id],-(1920-xpos)+n,ypos)
}
else
TotalSpaces2.move_window(
window[:window_id],1920, ypos)
TotalSpaces2.move_window_to_space(
window[:window_id], current_space)
TotalSpaces2.set_front_window(no_current_windows[0][:window_id])
0.step(off,5){|n| TotalSpaces2.move_window(
window[:window_id],1920-n,ypos)
}
end
sleep 0.2
}
end
$LOAD_PATH << '.'
alfred_move_windows("{query}")

Thanks!

Note that this requires TotalSpaces2 2.2.19 and version 2.2.1 of the API gem, which is not publicly released, but I’ll try to get it pushed asap. Ask me if you need it before.

Also a side note - this relies on the screen width being 1920, but you can discover your own width information with TotalSpaces2.display_list

This app is so wonderful!I like it very much
TKS FOR YOUR WORK!

So nice to hear, thank you!

Hi, Stephen,It’s me ,I am duoer1982, but gmail is not able to be use in china any more, So I sign up another account ;

I send you a e-mail and waiting for your reply;

I hope you received and give me a reply,the ruby API window_list can’t get “app_name”,So the function of move windows by Alfred is not working; I don’t know this problem is occurred by API or TotalSpaces2 .7.12

system information:

TotalSpaces2-2.7.12

Mojave 10.14.5

[duoer@~$] ruby ma.rb

TotalSpaces2 API version: 2.2.1

TotalSpaces2 windowsall: [{:window_id=>87, :title=>“ma.rb”, :frame=>"{{4, 0}, {1432, 900}}", :is_on_all_spaces=>false, :app_name=>"", :display_id=>69733824, :space_number=>2}, {:window_id=>83, :title=>"", :frame=>"{{508, 139}, {730, 520}}", :is_on_all_spaces=>false, :app_name=>"", :display_id=>69733824, :space_number=>2}, {:window_id=>119, :title=>“Maipo”, :frame=>"{{262, 65}, {432, 700}}", :is_on_all_spaces=>false, :app_name=>"", :display_id=>69733824, :space_number=>2}, {:window_id=>88, :title=>“NeteaseMusic”, :frame=>"{{182, 89}, {1002, 670}}", :is_on_all_spaces=>false, :app_name=>"", :display_id=>69733824, :space_number=>2},