API: Bug in window_list()?

Hi,

I’m trying to use TotalSpaces.window_list() as shown in the [documentation][1] and I’m getting an unexpected error:

% ./testTotalSpaces.rb
/Library/Ruby/Gems/1.8/gems/totalspaces-0.3/lib/totalspaces.rb:346:in `window_list': undefined method `force_encoding' for "/Volumes/xxxxx/Users/xxxxx/Downloads/2013-08-17":String (NoMethodError)
	from /Library/Ruby/Gems/1.8/gems/totalspaces-0.3/lib/totalspaces.rb:342:in `each'
	from /Library/Ruby/Gems/1.8/gems/totalspaces-0.3/lib/totalspaces.rb:342:in `window_list'
	from /Library/Ruby/Gems/1.8/gems/totalspaces-0.3/lib/totalspaces.rb:337:in `each'
	from /Library/Ruby/Gems/1.8/gems/totalspaces-0.3/lib/totalspaces.rb:337:in `window_list'
	from ./testTotalSpaces.rb:6

Here’s my script:

#!/usr/bin/env ruby
require 'rubygems'
require 'totalspaces'

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], TotalSpaces.current_space + 1)
end

The window mentioned in the error message is a Path Finder window.

Is this a bug, or am I missing something?

Thanks,

Philippe
[1]: http://binaryage.github.io/totalspaces-api/ruby/rdoc/TotalSpaces.html “documentation”

It’s expecting Ruby 1.9 or above.

Actually Ruby 1.8 is now retired: http://www.ruby-lang.org/en/news/2013/06/30/we-retire-1-8-7/

Is it possible for you to use a newer Ruby?

It may be possible to successfully use the API bindings in 1.8 by just removing the force_encoding(“UTF-8”) calls on lines 401-404 of totalspaces.rb - if you do not wish to upgrade ruby then this may be worth trying.

Got it, thank you! I’ll look into your suggested solutions.

OK, I gave up installing Ruby 2.0 after the nth error, but I got it working with Ruby 1.8 by commenting out all the occurrences of force_encoding() in totalspaces.rb.

I’m very happy, now, because I can send the front window to any space with a hot key. Thank you again. :slight_smile: