2017-10-12 5 views
0

MacOS(Sierra)でiTerm2を使用しています。私はiterm2の複数のインスタンスを実行している、それぞれは実行中のウィンドウごとに増分する数字の接頭辞が付いています。iTerm2のウィンドウ名/番号を確認する

コマンドラインでこの番号を返すシェルコマンドを実行したいと思いますが、この情報を取得する方法を知っている人はいますか?

私のようなものを探しています:私はAppleScriptを使用して名前を取得することができた

$ iterm_get_number() 
2 

答えて

0

は、次のスクリプトは、オープンITERMウィンドウのリストをダンプします。私はPythonスクリプトでこれらの名前を使用することに興味があるので、これを行うための小さなスニペットも含めました。上記のスクリプトから情報を抽出するための


get_window_names.applescript

on run 
    set returnNames to {} 
    tell application "iTerm" 
     repeat with theWindow in windows 
      tell theWindow 
       set end of returnNames to get name 
      end tell 
     end repeat 
    end tell 
    return returnNames 
end run 

パイソン

out = subprocess.check_output(['osascript', 'get_window_names.applescript']) 
print [x.strip() for x in out.split(',')]