I want to move current window to other spaces without changing space

Most of the time, I just wanna move current window to other spaces but I don’t
want to change space, can you give us another option?

2 Likes

I admit I did wonder if this would be something useful. But I haven’t actually had many requests for this. I will consider it though, it probably wouldn’t be too difficult to add “Send window to space” hotkeys.

Anyone else has this request?

Pls help me up this topic !

I think this would be a great time saver where you can “throw” the window off without having to initiate overview or change Space for now.

yes,throw window,haha

I implemented it using the API and Keyboard Maestro in the previous version of TotalSpaces, and I used it all the time. Can’t wait for an updated version of the API, BTW :slight_smile:

how to ? what API ?

The API will be here https://github.com/binaryage/totalspaces2-api/tree/master/ruby

I expect to finish testing it soon, I’ll release it as a pre-release as soon as it’s ready.

Flip​Martin, Could you share your ruby script? I do not understand ruby; I want to learn it;

I only use Ruby for this, so I’m definitely not an expert. But here are my scripts:

Get current space:

#!/usr/bin/env ruby

require 'rubygems'
require 'totalspaces'

current_space = TotalSpaces.current_space
puts "#{current_space}"

Switch to space:

#!/usr/bin/env ruby

require 'rubygems'
require 'appscript'
require 'totalspaces'

kme = Appscript.app('Keyboard Maestro Engine')
dest_space = kme.variables["spaces_dest"].value.get.to_i

TotalSpaces.move_to_space(dest_space)

Move front window to space (move the front window to the space whose number is in Keyboard Maestro’s variable spaces_dest, and switch to that space):

#!/usr/bin/env ruby

require 'rubygems'
require 'appscript'
require 'totalspaces'

kme = Appscript.app('Keyboard Maestro Engine')
dest_space = kme.variables["spaces_dest"].value.get.to_i
windows = TotalSpaces.window_list

if !windows.empty?
        current_space_windows = windows[TotalSpaces.current_space - 1]
        front_window = current_space_windows[:windows][0]
        TotalSpaces.move_window_to_space(front_window[:window_id], dest_space)
end

TotalSpaces.move_to_space(dest_space)

Send front window to space (send the front window to the space whose number is in Keyboard Maestro’s variable spaces_dest, but don’t switch to that space):

#!/usr/bin/env ruby

require 'rubygems'
require 'appscript'
require 'totalspaces'

kme = Appscript.app('Keyboard Maestro Engine')
dest_space = kme.variables["spaces_dest"].value.get.to_i
windows = TotalSpaces.window_list

if !windows.empty?
        current_space_windows = windows[TotalSpaces.current_space - 1]
        front_window = current_space_windows[:windows][0]
        TotalSpaces.move_window_to_space(front_window[:window_id], dest_space)
end

These scripts are executed from Keyboard Maestro’s “Execute Shell Script” actions. All of them except the first one use a variable set from Keyboard Maestro, but they could get the space’s number from elsewhere (from an environment variable, for example). In fact, you could even remove the references to Keyboard Maestro (and appscript), make a copy of the script for each of your spaces, and have the space number hardcoded in each.

Hope this helps. Good luck!

BTW Stephen, any ETA?

Edit: never mind, I found the post where you linked to it. :slight_smile:

The scripts I posted above are those I used for TotalSpaces. Here are them converted for TotalSpaces2.

Get current space:

#!/usr/bin/env ruby

require 'rubygems'
require 'totalspaces2'

current_space = TotalSpaces2.current_space
puts "#{current_space}"

Switch to space:

#!/usr/bin/env ruby

require 'rubygems'
require 'appscript'
require 'totalspaces2'

kme = Appscript.app('Keyboard Maestro Engine')
dest_space = kme.variables["spaces_dest"].value.get.to_i

TotalSpaces2.move_to_space(dest_space)

Move front window to space (move the front window to the space whose number is in Keyboard Maestro’s variable spaces_dest, and switch to that space):

#!/usr/bin/env ruby

require 'rubygems'
require 'appscript'
require 'totalspaces2'

kme = Appscript.app('Keyboard Maestro Engine')
dest_space = kme.variables["spaces_dest"].value.get.to_i
current_space = TotalSpaces2.current_space
windows = TotalSpaces2.window_list

if !windows.empty?
        current_space_windows = windows.select {
		|window| window[:space_number] == current_space
	}
        front_window = current_space_windows[0]
        TotalSpaces2.move_window_to_space(
		front_window[:window_id], dest_space
	)
end

TotalSpaces2.move_to_space(dest_space)

Send front window to space (send the front window to the space whose number is in Keyboard Maestro’s variable spaces_dest, but don’t switch to that space):

#!/usr/bin/env ruby

require 'rubygems'
require 'appscript'
require 'totalspaces2'

kme = Appscript.app('Keyboard Maestro Engine')
dest_space = kme.variables["spaces_dest"].value.get.to_i
current_space = TotalSpaces2.current_space
windows = TotalSpaces2.window_list

if !windows.empty?
        current_space_windows = windows.select {
		|window| window[:space_number] == current_space
	}
        front_window = current_space_windows[0]
        TotalSpaces2.move_window_to_space(
		front_window[:window_id], dest_space
	)
end

Note that the only change in the first two is the addition of ‘2’ in each occurrence of ‘TotalSpace’, and the only difference between the last two is the last line.

Flip​Martin,TKS very much!

#!/usr/bin/env ruby
when I exe the script,shell tell me:

2014-03-01 19:42:42.947 ruby[4009:1a03] Could not create connection to TotalSpaces
0

Did you install the API with something like ‘sudo gem install totalspaces2’?

If you haven’t, check these pages:


http://binaryage.github.io/totalspaces2-api/ruby/rdoc/TotalSpaces2.html

[duoer@ ~]$ gem list
gems I have installed

Is there anything else I forget?
*** LOCAL GEMS ***

CFPropertyList (2.2.0)
ffi (1.9.3)
libxml-ruby (2.6.0)
nokogiri (1.5.6)
sqlite3 (1.3.7)
totalspaces2 (2.0)

The only thing you’re missing compared to what I have is rb-appscript (0.6.1), but it’s not used in this script:

*** LOCAL GEMS ***

CFPropertyList (2.2.0)
ffi (1.9.3)
libxml-ruby (2.6.0)
nokogiri (1.5.6)
rb-appscript (0.6.1)
sqlite3 (1.3.7)
totalspaces2 (2.0)

Maybe the problem comes from the shebang: “#!/usr/bin/env ruby” tells the shell to use the ruby whose path comes first in your PATH environment variable, so if you have several versions of ruby installed, make sure this is the case. Otherwise, try “#!ruby” instead.

It does not work even use #!ruby;

just only one version of ruby: ruby 2.0.0p247 (2013-06-27 revision 41674)

HELP!stephen

@duoer1982 : Did you figure it out?

We had some direct correspondence - it does work now.

Cool!