[英]Wait for a GUI application to fully startup before running script
If I have something like this in a bash
script: 如果我在
bash
脚本中有这样的内容:
audacity &
pid=$!
wmctrl -r "Audacity" -e 0,0,0,800,600
... it will usually fail, because the process startup ( audacity &
) will finish/return much earlier than the point where the Audacity window is fully shown (and can be controlled by wmctrl
), which otherwise may take a couple of seconds. ...它通常会失败,因为进程启动(
audacity &
)将比完全显示Audacity窗口(并可以通过wmctrl
进行控制)早得多的时间完成/返回,否则可能要花费几秒钟。
Is there an easy way to "sync" or "wait" for a GUI application to be fully started up (that is, its window being fully rendered), before proceeding with a script? 在继续执行脚本之前,是否有一种简单的方法可以“同步”或“等待” GUI应用程序完全启动(即其窗口已完全呈现)? ( there is a way I've found, which I'm posting as an answer - but was wandering if there is an easier, more compact way )
( 我找到了一种方法,我将其发布为答案-但如果有一种更简单,更紧凑的方法,我一直在徘徊 )
EDIT: this does detect when the window is shown; 编辑:这确实检测何时显示窗口; but does not detect when all the menus/widgets inside it are finished with placement/layout
但无法检测其中所有菜单/小部件的放置/布局是否完成
Ok, so first I run this script: 好的,所以首先我运行以下脚本:
audacity &
pid=$!
while [ "1" ] ; do
xwininfo -name 'Audacity'
sleep 0.1
done
... which should be run like this, to obtain a full log: ...应该这样运行,以获得完整的日志:
bash testscript.sh 2>&1 | tee testscript.log
... and can see a point, where the dump from xwininfo
"transitions", so to speak: ...可以看到一点,可以说
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
So, I could basically grep
for xwininfo
output not containing "has no name", or containing "Map State: IsViewable" ... 因此,我基本上可以为不包含“没有名称”或包含“地图状态:IsViewable”的
xwininfo
输出设置grep
...
So, I finally try this - and it seems to work: 所以,我终于尝试了这一点-似乎可行:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.