rrt44 发表于 2015-12-16 09:14:37

Totalspaces2+Alfred: send windows to other spaces

F1: 移动当前窗口到左边SPACE

require 'totalspaces2'
current_spaces = TotalSpaces2.current_space
windows = TotalSpaces2.window_list
if current_spaces > 1
dest_space = current_spaces - 1
else
dest_space = 4
end


if !windows.empty?
    current_space_windows = windows.select {
    |window| window[:space_number] == current_spaces
   }
end


if current_space_windows
      win_pra = (current_space_windows[:frame].delete"\{\} ").split(',')
      xpos =win_pra.to_i
      ypos =win_pra.to_i
      off=(1920 - win_pra.to_i)
      0.step(off,8){|n| TotalSpaces2.move_window(
      current_space_windows[:window_id],xpos-n,ypos)
      }
      TotalSpaces2.move_window_to_space(
            current_space_windows[:window_id],dest_space)
      if current_space_windows
         TotalSpaces2.set_front_window(current_space_windows[:window_id])
      end
      2.times{TotalSpaces2.move_window(
         current_space_windows[:window_id],xpos, ypos)
       sleep 0.1}
end   

F2: 移动当前窗口到右边SPACE
require 'totalspaces2'
current_spaces = TotalSpaces2.current_space
windows = TotalSpaces2.window_list
if current_spaces < 4
dest_space = current_spaces + 1
else
dest_space = 1
end


if !windows.empty?
    current_space_windows = windows.select {
    |window| window[:space_number] == current_spaces
   }
end


if current_space_windows
      win_pra = (current_space_windows[:frame].delete"\{\} ").split(',')
      xpos =win_pra.to_i
      ypos =win_pra.to_i
      off=(1920 - win_pra.to_i)
      0.step(off,8){|n| TotalSpaces2.move_window(
      current_space_windows[:window_id],xpos+n,ypos)
      }
      TotalSpaces2.move_window_to_space(
            current_space_windows[:window_id],dest_space)
      if current_space_windows
         TotalSpaces2.set_front_window(current_space_windows[:window_id])
      end
      2.times{TotalSpaces2.move_window(
         current_space_windows[:window_id],xpos, ypos)
       sleep 0.1}
end   

F3: 移动非活动窗口到右边SPACE

#!/usr/bin/ruby
require 'totalspaces2'
current_spaces = TotalSpaces2.current_space
windowslist = TotalSpaces2.window_list


if current_spaces < 4
dest_space = current_spaces + 1
else
dest_space = 1
end


if !windowslist.empty?
current_space_windows = windowslist.select {
    |window| window[:space_number] == current_spaces
}
current_space_windows.each_with_index{
    |list,index| if index > 0
      win_pra = (list[:frame].delete"\{\} ").split(',')
      xpos =win_pra.to_i
      ypos =win_pra.to_i
      off=(1920 - win_pra.to_i)
      0.step(off,10){|n| TotalSpaces2.move_window(
      list[:window_id],xpos+n,ypos)
       }
      TotalSpaces2.move_window_to_space(
      list[:window_id], dest_space)
      2.times{TotalSpaces2.move_window(
      list[:window_id],xpos, ypos)
      sleep 0.1
      }
    end
    }
end
页: [1]
查看完整版本: Totalspaces2+Alfred: send windows to other spaces