我使用 Cheese 作为我的网络摄像头软件。我正在尝试找出一种方法来获得它:
- 开始
- 单击图片
- 出口
当执行脚本时。该脚本不应请求权限,也不应有任何中断。迄今为止,
#!/bin/bash
cheese
我只能让它执行步骤 1。我该如何执行步骤 2 和 3?文档文件没有提到这样的选项,我不想更改源代码。 (我也不介意相机)
答案1
瞧!步骤 2 和 3 如下:
这是有效的,尽管它对时间非常关键,根据您认为合适的情况进行调整,尝试适当地评论它,以便您可以看到发生了什么。
你需要安装xdo工具为此,我们正在模拟按键来拍照并退出(包'xdo工具')
哦,你需要关闭'倒数' 功能在首选项中,否则它可能会在实际拍摄之前按 CTRL-Q(退出)退出程序。
#!/bin/bash
#
# L Nix <[email protected]>
# takeapic : take a photo with Cheese, using default settings, then exit
#
# start cheesing (2> because mine whines about cheesy stuff (ha!))
cheese 2>/dev/null &
# give WM some time to start up program (fails without this)
sleep 5
# set so we can determine if valid window(s) exist(s)
WINDOWIDS=""
# wait for up to 90 seconds (tweak this)
COUNTDOWN=90
while [ ${COUNTDOWN} -gt 0 ]; do
WINDOWIDS=$(xdotool search --class "cheese" 2>/dev/null)
if [ -n "${WINDOWIDS}" ]; then
break
fi
sleep 1
COUNTDOWN=$(( ${COUNTDOWN} - 1 ))
done
# did we get anything?
if [ -z "${WINDOWIDS}" ]; then
echo "Cheese never started, something's wrong"
exit 1
fi
# the shutter button is ALT-T
for WIDS in ${WINDOWIDS}; do
# if you combine these like xdotool allows, it fails
xdotool windowfocus ${WIDS} 2>/dev/null
xdotool key alt+t 2>/dev/null
done
# pause a moment while taking photo
sleep 1
# now CTRL-Q out of the application
for WIDS in ${WINDOWIDS}; do
xdotool windowfocus ${WIDS} 2>/dev/null
xdotool key ctrl+q 2>/dev/null
done
#