coteditor / cot

Command-line helper tool for CotEditor
https://coteditor.com/cot
Apache License 2.0
55 stars 11 forks source link

cot -w raises subprocess.CalledProcessError on exit with iTerm2 #9

Closed r6e closed 5 years ago

r6e commented 5 years ago

Issue and Steps to Reproduce

When using cot -w within iTerm2, cot raises a subprocess.CalledProcessError when the applicable window is closed or CotEditor is exited (see screenshots). This is not resolved using the steps detailed in CotEditor issue #877.

Error Text

Traceback (most recent call last):
  File "/usr/local/bin/cot", line 411, in <module>
    main(args, stdin)
  File "/usr/local/bin/cot", line 393, in main
    client_window_id))
  File "/usr/local/bin/cot", line 141, in tell
    raise error
subprocess.CalledProcessError: Command 'tell app "iTerm2" to set frontmost of window id 49908 to true' returned non-zero exit status 1

Steps to Reproduce

From within iTerm2:

  1. $ touch test.txt
  2. $ cot -w test.txt
  3. Exit CotEditor
  4. Note the error in iTerm2.

Possible Cause

This appears to be caused by lines 315 and 136.

On line 315, client_name is set to the process name, which in the case of iTerm2 is iTerm2. However, on line 136, the generated script references the app name, which for iTerm2 is iTerm. The result is that osascript can not find the correct app and fails.

Possible Solution

If the cause above is correct, then this is due to iTerm2's unusual conventions. However, since these conventions are still valid, it might make sense to account for them in cot.

This could potentially be fixed by using consistent references to refer to the client app; either always the app name or the process name. However, I am not too familiar with osascript, so this may not be possible or reasonable, depending on context.

Versions

Screenshots

Reproducing Error

cot_error

macOS Privacy Settings

Included to verify this isn't caused by CotEditor #877

screen shot 2019-01-09 at 13 47 29
1024jp commented 5 years ago

Thank you for the perfect issue report. As you mentioned, --wait failed because the application name and process name are different in iTerm. So, I changed to invoke the client not by application name but by the path to the application. This way is more reliable not only for iTerm but also for cases such as when there are more than two applications whose name are the same in different places.

I'll ship this fix with the next CotEditor, which will be released in the next week. Thank you!