所以我无法加载外部软件,因为这是一个用于在设置时测试新mac工作站的脚本,并且脚本记录每个测试的通过/失败/空(跳过)状态。除鼠标移动外,我完成了一切。因为这是为了工作,设置技术人员必须运行此脚本,并且他们没有超级用户权限,并且需要在USB驱动器上携带。这可能吗?
编辑细节:
我有多个工作站正在接受技术人员的测试,他们四处走动并将他们的机器连接到码头。它测试内部和外部网络,以及键盘鼠标和声音。我有键盘和网络的东西。我还在学习如何使用文字转语音引擎播放声音,并询问用户是否播放。到目前为止的所有数据都写为变量,然后保存到csv。我正在编写csv部分,因为我正在与管理层合作,希望如何显示数据。
TLDR Tech移动鼠标,我需要检查鼠标是否在脚本中移动并写入通过/失败
下面是我的代码(略微修改以保留隐私)
#!/bin/bash
#this pulls the logged in user's name.
runninguser=$(whoami)
#end of line
#script version
scrver="script version 0.0.1"
#end script version
#welcome text
echo Welcome to the Mac Install Test Script, by [ME]. This is $scrver
#end welcome text
# this section is what makes the directory where the files will
# be temporarily saved to.
mkdir -p ~/tmp
#this section asks for tech's last name and first name
echo Hi $runninguser, I am the Mac Automated Test Script. Nice to meet you!
# This section is for getting the customer name
echo "What is your customer's last name for this workstation?"
read custLname
echo "Thank you, now what is your customer's first name?"
read custFname
# This section is for testing to see if the internet connection works.
echo "Now we are going to test the external network connection."
curl -o ~/tmp/elgoogs http://www.google.com
testout1=~/tmp/elgoogs
if grep -q "/body" "$testout1"
then echo "pass" && internettest="PASS"
else echo "fail" && internettest="FAIL"
fi
#this section is for testing the internal network connection
curl -o ~/tmp/[REDACTED] http://[REDACTED].gov
testin1=~tmp/[REDACTED]
if grep -q "/body" "$testin1"
then echo "pass" && intranettest="PASS"
else echo "fail" && intranettest="FAIL"
fi
#The next section is for keyboard testing
echo "We are now going to test the keyboard"
sleep 2
echo "Please press the enter key!"
while true; do
read -rsn1 kinput
if [ "$kinput" = “” ]; then
echo "keyboard test passed!" && kbtest="PASS" && break
fi
done
# VARIABLES & STRINGS
#
# testout1 is filepath for internet test
# internettest is the pass/fail state for outside network testing.
# runninguser is the currently running user
# scver is the version of the script being run
# custLname is the Customer's Last Name
# custFname is the Customer's First Name
# testin1 is the intranet test
# intranettest is the pass/fail state for inside network testing.
# kinput is the input variable, what is being waited for.
# kbtest is the pass/fail state for keyboard test
#
答案 0 :(得分:1)
不是告诉用户移动鼠标并尝试读取其位置,而是弹出一个对话框,要求他们移动鼠标并单击OK
,这同样可以证明它有效。如果鼠标不起作用,您也可以告诉用户使用TAB和Enter选择Cancel
。
所以,来自bash
osascript -e 'tell app "System Events" to display dialog "Mouse over OK button and click it, or use TAB and Enter to select Cancel if mouse does not work" buttons {"Cancel", "OK"}'
以下是一个略有不同的示例,其中包含PASS
和FAIL
按钮以及标题,并在bash
变量中捕获结果:
#!/bin/bash
#this pulls the logged in user's name.
runninguser=$(whoami)
#end of line
...
...
# Test mouse responds
result=$(osascript -e 'tell app "System Events" to display dialog "Mouse over PASS button and click it, or use TAB and Enter to select FAIL if mouse does not work" with title "Mouse Test" buttons {"FAIL", "PASS"} default button 1')
echo $result
button returned:PASS