2013-10-18 47 views
1

之前完全啓動。如果我有一個bash腳本是這樣的:等待一個GUI應用程序來運行腳本

audacity & 
pid=$! 

wmctrl -r "Audacity" -e 0,0,0,800,600 

...它通常會失敗,因爲該進程啓動(audacity &)將完成/返回比Audacity窗口完全顯示的點早得多(並且可以由wmctrl控制),否則可能需要幾秒鐘。

在繼續執行腳本之前,是否有一種簡單的方法可以讓GUI應用程序「同步」或「等待」以完全啓動(即,其窗口已完全呈現)? (有一種方法,我找到了,我發佈作爲答案 - 但徘徊,如果有一個更容易,更緊湊的方式

回答

1

編輯:這會檢測何時顯示窗口;但是當所有的菜單/裏面的部件都完成了佈局/佈局

確定沒有檢測,所以首先我運行此腳本:

audacity & 
pid=$! 

while [ "1" ] ; do 
    xwininfo -name 'Audacity' 
    sleep 0.1 
done 

...應該是這樣運行,以獲得一個完整的日誌:

bash testscript.sh 2>&1 | tee testscript.log 

...並可以看到一個點,其中來自xwininfo 「過渡」,轉儲可以這麼說:

xwininfo: Window id: 0x3a000b5 (has no name) 

    Absolute upper-left X: 0 
    Absolute upper-left Y: 0 
    Relative upper-left X: 0 
    Relative upper-left Y: 0 
    Width: 200 
    Height: 200 
    Depth: 24 
    Visual: 0x21 
    Visual Class: TrueColor 
    Border width: 0 
    Class: InputOutput 
    Colormap: 0x20 (installed) 
    Bit Gravity State: NorthWestGravity 
    Window Gravity State: NorthWestGravity 
    Backing Store State: NotUseful 
    Save Under State: no 
    Map State: IsUnMapped 
    Override Redirect State: no 
    Corners: +0+0 -824+0 -824-400 +0-400 
    -geometry 200x200+0+0 

xwininfo: Window id: 0x4c00587 "Audacity" 

    Absolute upper-left X: 50 
    Absolute upper-left Y: 59 
    Relative upper-left X: 0 
    Relative upper-left Y: 18 
    Width: 830 
    Height: 540 
    Depth: 24 
    Visual: 0x21 
    Visual Class: TrueColor 
    Border width: 0 
    Class: InputOutput 
    Colormap: 0x20 (installed) 
    Bit Gravity State: NorthWestGravity 
    Window Gravity State: NorthWestGravity 
    Backing Store State: NotUseful 
    Save Under State: no 
    Map State: IsViewable 
    Override Redirect State: no 
    Corners: +50+59 -144+59 -144-1 +50-1 
    -geometry 830x540+50-1 

所以,我基本上可以grep不包含xwininfo輸出「沒有名字」,或者包含「映射的狀態:IsViewable」 ......

所以,我終於嘗試這一點 - 它似乎工作:

audacity & 
pid=$! 

WINREP="" 
while [[ ! "`echo $WINREP | grep -l 'Map State: IsViewable'`" ]] ; do 
    WINREP=$(xwininfo -name 'Audacity') 
    #echo $WINREP 
    sleep 0.1 
done 

echo Exited 

# must use -F here for case-insensitive, to ensure proper window targetting 
wmctrl -v -F -r "Audacity" -e 0,0,0,800,600 
相關問題