2016-08-29 9 views
1

다음 스크립트를 사용하여 창을 세로로 분할하고 새 창에서 로그 파일을 꼬리십시오.Applescript : 스크립트가 호출 된 창에서 창을 분할하는 iTerm

#!/bin/bash 

COMMAND="tail -f log_file" 

# Do something important. 
sleep 4 

# Split the window, and tail logs. 
osascript <<-EOF 
tell application "iTerm" 
    tell current session of current window 
     split vertically with default profile command "$COMMAND" 
    end tell 
end tell 
EOF 

그러나이 스크립트는 현재 포커스가있는 창을 분할하고 스크립트가 실행되는 창을 분할하지 않습니다.

  1. 을 엽니하여 ITerm 창 (W1 말),이 스크립트를 실행

    단계 문제를 재현합니다.

  2. 스크립트가 sleep 4을 실행하는 동안 다른 창 (예 : W2)을 열고 W2에 포커스를 유지합니다.
  3. 4 초 후에 더 새로운 창 (예 : W2)이 세로로 분할됩니다.

W1에서 스크립트를 호출 한 창을 열려면 어떻게해야합니까?

답변

1

스크립트의 시작 부분에서 현재 세션의 ID를 가져옵니다. 나중에 스크립트

은 감사를

#!/bin/bash 
myID=$(osascript -e 'tell application "iTerm" to id of current session of current window') 

COMMAND="tail -f log_file" 

# Do something important. 
sleep 4 

# Split the window, and tail logs. myID2 is the id of the new session (the split pane) 
myID2=$(osascript <<-EOF 
tell application "iTerm" 
    repeat with w in windows 
     repeat with t in tabs of w 
      tell (first session of t whose its id = "$myID") 
       if exists then return id of (split vertically with default profile command "$COMMAND") 
      end tell 
     end repeat 
    end repeat 
end tell 
EOF) 
+0

작품 완벽하게이 식별자에 대응하는 세션을 얻을. 같은 ID를 가진 여러 개의 창이 존재할 가능성이 있습니까? –

+0

아니요, 식별자가 고유합니다. – jackjr300