consular-iterm icon indicating copy to clipboard operation
consular-iterm copied to clipboard

dosen't work with latest iterm?

Open kevzettler opened this issue 9 years ago • 17 comments

/Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rb-scpt-1.0.1/lib/rb-scpt.rb:676:in `rescue in method_missing': Unknown property, element or command: 'current_terminal' (RuntimeError)
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rb-scpt-1.0.1/lib/rb-scpt.rb:646:in `method_missing'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:300:in `active_window'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:293:in `active_tab'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:131:in `block in execute_window'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:122:in `each'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:122:in `execute_window'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:57:in `process!'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-1.0.3/lib/consular/cli.rb:35:in `block in start'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-1.0.3/lib/consular/cli.rb:255:in `call'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-1.0.3/lib/consular/cli.rb:255:in `message_unless_file'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-1.0.3/lib/consular/cli.rb:35:in `start'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Users/kevzettler/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/consular-1.0.3/bin/consular:13:in `<top (required)>'
    from /Users/kevzettler/.rbenv/versions/2.2.2/bin/consular:22:in `load'
    from /Users/kevzettler/.rbenv/versions/2.2.2/bin/consular:22:in `<main>'

kevzettler avatar Jun 12 '16 20:06 kevzettler

Hi there, could you share what your iterm version is and what command produced this output?

I wasn't able to reproduce this with iterm 3.0.0 on El Capitan with Ruby 2.3.1 and consular-iterm 1.0.3.

eric-hu avatar Jun 13 '16 11:06 eric-hu

I'm getting the same issues using iTerm 3.0.0 on OSX 10.10.5 with Ruby 2.1.3 and consular-iterm 1.0.3.

JustinTBrown avatar Jun 16 '16 16:06 JustinTBrown

Thanks for the additional data point. Is there any particular command that breaks for you? Is it everything?

eric-hu avatar Jun 19 '16 19:06 eric-hu

Okay, I can reproduce on my system using consular setup <name>.

I debugged this a little by throwing a binding.pry in before the erroring line from this project. It looks like current_terminal is not defined. However, current_window and current_tab are.

[14] pry(#<Consular::ITerm Mac OSX iTerm2>)> @terminal
=> app("/Applications/iTerm.app")
[15] pry(#<Consular::ITerm Mac OSX iTerm2>)> @terminal.current_tab
=> app("/Applications/iTerm.app").current_tab
[16] pry(#<Consular::ITerm Mac OSX iTerm2>)> @terminal.current_window
=> app("/Applications/iTerm.app").current_window
[17] pry(#<Consular::ITerm Mac OSX iTerm2>)> @terminal.current_window.class
=> Appscript::Reference
[18] pry(#<Consular::ITerm Mac OSX iTerm2>)> @terminal.current_tab.class
=> Appscript::Reference

I think changing current_terminal to reference current_window will preserve the intended behavior. It looks like active_tab might need to be changed too.

I'd like to investigate the cause of this change. I recall this working before the new iterm build. This might require an iterm version check to preserve backwards compatibility.

eric-hu avatar Jun 20 '16 06:06 eric-hu

Ok, thanks. I get it when running consular start, but not other commands like edit or list

JustinTBrown avatar Jun 20 '16 18:06 JustinTBrown

Unfortunately when I experimented with it briefly, I can't easily check for the existence of these methods because they're meta-programmed:

[20] pry(#<Consular::ITerm Mac OSX iTerm2>)> defined?(@terminal.current_window)
=> nil
[21] pry(#<Consular::ITerm Mac OSX iTerm2>)> defined?(@terminal.current_terminal)
=> nil
...
[23] pry(#<Consular::ITerm Mac OSX iTerm2>)> @terminal.current_window
=> app("/Applications/iTerm.app").current_window

It can be checked for this way:

[24] pry(#<Consular::ITerm Mac OSX iTerm2>)> @terminal.instance_variable_get(:@AS_app_data).instance_variable_get(:@reference_by_name).keys.include?(:current_window)
=> true

On first inspection, rb-scpt proxies Iterm2 (ObjC?) variables into Ruby via method_missing?. The check above does reveal if current_window is defined, but it looks extremely brittle. I'm not sure whether it's better to drop support for Iterm2 prior to version 3, or to try to support it. Any thoughts @achiu ?

eric-hu avatar Jun 20 '16 19:06 eric-hu

If anyone is willing to submit a working pull request for version 3 support of Iterm, we'll gladly accept it. We can also lock iTerm v2 support to the current tag and make a note of it in the README for users that may prefer version 2 of iTerm.

achiurizo avatar Jun 20 '16 20:06 achiurizo

I've figured out enough to get consular start working for simple tasks. It's broken for opening a new tab, though.

That fails with:

/Users/erichu/.gem/ruby/2.3.1/gems/rb-scpt-1.0.1/lib/rb-scpt.rb:676:in `rescue in method_missing': Unknown property, element or command: 'launch_' (RuntimeError)
    from /Users/erichu/.gem/ruby/2.3.1/gems/rb-scpt-1.0.1/lib/rb-scpt.rb:646:in `method_missing'
    from /Users/erichu/.gem/ruby/2.3.1/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:258:in `open_tab'
    from /Users/erichu/.gem/ruby/2.3.1/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:131:in `block in execute_window'
    from /Users/erichu/.gem/ruby/2.3.1/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:122:in `each'
    from /Users/erichu/.gem/ruby/2.3.1/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:122:in `execute_window'
    from /Users/erichu/.gem/ruby/2.3.1/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:57:in `process!'
    from /Users/erichu/.gem/ruby/2.3.1/gems/consular-1.0.3/lib/consular/cli.rb:35:in `block in start'
    from /Users/erichu/.gem/ruby/2.3.1/gems/consular-1.0.3/lib/consular/cli.rb:255:in `message_unless_file'
    from /Users/erichu/.gem/ruby/2.3.1/gems/consular-1.0.3/lib/consular/cli.rb:35:in `start'
    from /Users/erichu/.gem/ruby/2.3.1/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/erichu/.gem/ruby/2.3.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/erichu/.gem/ruby/2.3.1/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/erichu/.gem/ruby/2.3.1/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Users/erichu/.gem/ruby/2.3.1/gems/consular-1.0.3/bin/consular:13:in `<top (required)>'
    from /Users/erichu/.gem/ruby/2.3.1/bin/consular:23:in `load'
    from /Users/erichu/.gem/ruby/2.3.1/bin/consular:23:in `<main>'

I'm not sure how to begin debugging the API change, as there isn't a launch_ method in rb-scpt, so that must have been a mapping to Iterm2 prior to version 3. The change might be discoverable by comparing the Iterm2 3.0.2 tag to some earlier version, kind of like this.

If it will move things forward, I can submit a PR with what I have to enable partial Iterm2 v3 support, and open a new issue for the tabs not opening. What do you think @achiu ?

eric-hu avatar Jun 22 '16 16:06 eric-hu

If it will move things forward, I can submit a PR with what I have to enable partial Iterm2 v3 support, and open a new issue for the tabs not opening. What do you think @achiu ?

:+1: I think that's a reasonable start.

rb-scpt proxies Iterm2 (ObjC?) variables into Ruby via method_missing?. The check above does reveal if current_window is defined, but it looks extremely brittle

I think it also might be time to drop rb-scpt and look for alternative ways to achieve this.(maybe have the consular DSL translate into apple script directly and invoke it.)

achiurizo avatar Jun 23 '16 13:06 achiurizo

Ah okay, my brain wasn't working when I wrote that comment. Rb-scpt proxies the appscript interface for iterm2, and the documentation for iterm2 Applescript is here.

I updated my PR with fixes for opening a new tab and opening a new window. I confirmed these with manual testing. It'd be nice to add automated tests around these changes, but the only valuable tests I could think of would require integrating with iterm, and could be easily polluted by user interactions.

eric-hu avatar Jun 25 '16 08:06 eric-hu

I just merged in a fix for all the issues I could spot. @kevzettler @JustinTBrown Can you guys try out the master branch of this repo and let us know if that fixes your issues? If so, I can bump the version and mark this as closed.

eric-hu avatar Jun 29 '16 02:06 eric-hu

Just manually pulled in the update to master. consular start now launches the first pane specified in my config, but then crashes:

/Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/rb-scpt-1.0.1/lib/rb-scpt.rb:542:in `_send_command': CommandError (Appscript::CommandError)
        OSERROR: -1728
        MESSAGE: Can't get reference.
        OFFENDING OBJECT: app("/System/Library/CoreServices/System Events.app").processes["iTerm"]
        COMMAND: app("/System/Library/CoreServices/System Events.app").processes["iTerm"].menu_bars.first.menu_bar_items["Shell"].menus["Shell"].menu_items["Split Vertically with Current Profile"].click()
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/rb-scpt-1.0.1/lib/rb-scpt.rb:642:in `method_missing'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:327:in `call_ui_action'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:223:in `vertical_split'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:175:in `block in top_level_pane_split'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:171:in `each'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:171:in `top_level_pane_split'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:157:in `execute_panes'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:140:in `block in execute_window'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:122:in `each'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:122:in `execute_window'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-iterm-1.0.3/lib/consular/iterm.rb:57:in `process!'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-1.0.3/lib/consular/cli.rb:35:in `block in start'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-1.0.3/lib/consular/cli.rb:255:in `call'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-1.0.3/lib/consular/cli.rb:255:in `message_unless_file'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-1.0.3/lib/consular/cli.rb:35:in `start'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/gems/consular-1.0.3/bin/consular:13:in `<top (required)>'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/bin/consular:22:in `load'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/bin/consular:22:in `<main>'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `eval'
    from /Users/justinbrown/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `<main>'

UPDATE: It should be noted I have never manually installed a gem before (I typically rely on gem install). So for this I simply looked up my gem paths using gem env, renamed consular-iterm-1.0.3 to consular-iterm-1.0.3.bak and then cloned this repo's master branch into consular-iterm-1.0.3. Let me know if that's a weird/incorrect way to do it.

JustinTBrown avatar Jul 04 '16 17:07 JustinTBrown

It works for me. Thanks.

kyamaguchi avatar Jul 08 '16 14:07 kyamaguchi

@JustinTBrown you can also git clone this repo and then rake install to install this gem. I can't say if your way is incorrect or even weird :)

Would you mind sharing your consular scripts? Feel free to scrub file names, folder names, and anything else. It will help me to make sure the commands you're using are all updated with the new iterm API.

eric-hu avatar Jul 13 '16 10:07 eric-hu

After installing the latest consular-iterm (following @JustinTBrown's method above), I'm getting the same _send_command error as him. Is there another method for installing the latest version of consular-iterm?

mgeraci avatar Aug 16 '16 13:08 mgeraci

@mgeraci You have the latest version regarding this issue. I haven't put time into fixing the additional consular-iterm commands that are giving Justin those errors.

Work and side project commitments have taken up my time for at least the next month. If anyone would like to try fixing the remaining commands (or for myself later on), here's what I recall:

Iterm2 v3 changed some of its Applescript API names and possibly abstractions. Rb-scpt maps iterm2's Applescript API calls into Ruby method calls. Iterm2 has an API documentation page here. The bottom of that page contains some pre v3 Applescript syntax.

As seen by the last merged PR, not all commands have to be fixed at once. Fixing one or a few commands would be an improvement for some users.

eric-hu avatar Aug 23 '16 09:08 eric-hu

Thanks for the info, Eric; I'll put it on my list of things to check out!

mgeraci avatar Aug 23 '16 13:08 mgeraci