我正在尝试xdotool
从 root shell 在用户显示器上执行操作(移动鼠标),但我得到:
# DISPLAY=:0 mousemove_relative 1 1
No protocol specified
Error:Can't open display: (null)
Failed creating new xdo instance
#
为什么这不起作用?
剧本:
#!/bin/bash
exec=`/usr/sbin/nethogs -t -c 1| awk '/smbd/ {print $2}'`
sent=$exec
echo "result: "$sent
sent=$(echo "($sent+0.5)/1" | bc)
echo "rounded: "$sent
if [[ $sent -gt 0 ]]
then
echo "music is playing"
`DISPLAY=:0 xdotool mousemove_relative 1 1`
else
echo "quiet"
fi
我得到这个/var/mail/root
:
Waiting for first packet to arrive (see sourceforge.net bug 1019381)
result: 6.73438
rounded: 7
music is playing
No protocol specified
Error: Can't open display: (null)
Failed creating new xdo instance
答案1
我必须将以下内容添加到脚本中:
export DISPLAY=:0
export XAUTHORITY=/home/username/.Xauthority