如果我在bash
脚本中有这样的内容:
audacity &
pid=$!
wmctrl -r "Audacity" -e 0,0,0,800,600
...它通常会失败,因为进程启动(audacity &
)将比完全显示Audacity窗口的时间更早完成/返回(并且可以由wmctrl
控制)否则可能需要几秒钟。
在继续编写脚本之前,是否有一种简单的方法可以“同步”或“等待”GUI应用程序完全启动(即,它的窗口是否完全呈现)? (有一种我找到的方式,我将其作为答案发布 - 但如果有一种更简单,更紧凑的方式就会徘徊)
答案 0 :(得分: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
输出不包含"没有名称"或者包含" Map State: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