Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用BASH(mac)查找鼠标指针位置?_Bash_Macos_Scripting - Fatal编程技术网

如何使用BASH(mac)查找鼠标指针位置?

如何使用BASH(mac)查找鼠标指针位置?,bash,macos,scripting,Bash,Macos,Scripting,因此,我不能加载外部软件,因为这是一个脚本,用于在新的mac工作站设置时测试它们,并且该脚本记录每个测试的通过/失败/空跳过状态。除了鼠标移动之外,我什么都有。因为这是为了工作,安装技术人员必须运行此脚本,他们没有超级用户权限,并且需要在USB驱动器上随身携带。这可能吗 有关详细信息,请编辑: 我有多个工作站,当技术人员四处走动并将他们的机器连接到码头时,他们正在测试这些工作站。它测试内部和外部网络,以及键盘鼠标和声音。我有键盘和网络设备。我仍在学习如何使用文本到语音引擎来播放声音,并询问用户是

因此,我不能加载外部软件,因为这是一个脚本,用于在新的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
#

与其告诉用户移动鼠标并尝试读取其位置,不如弹出一个对话框,让他们移动鼠标并单击“确定”,这同样可以证明它是有效的。如果鼠标不工作,您还可以告诉用户使用TAB和Enter选择Cancel

那么,从bash

下面是一个稍有不同的示例,带有“通过”和“失败”按钮,还有一个标题,它在一个变量中捕获结果:


bash本身没有任何对工作有用的东西,甚至在某种意义上,bash也没有任何其他语言能够启动子进程并读取它们的输出。好吧,这是有道理的。你打算如何向前推进?一个好的起点是提供足够的细节,让别人知道你真正想要什么。你是否有一个用户在操作鼠标,而你正在试图弄清楚它是否工作?一个模拟设备的脚本,你想知道它是否有效?具体说明你要完成的工作,不要太具体说明你想使用什么工具来完成这项工作,这样别人就可以为你的工作提供最好的工具,而不是最符合你对解决方案的先入之见的工具。在这里,我添加了代码,对其进行了轻微修改,以保留隐私和tldr。希望有帮助,明白了。简而言之:你最好使用AppleScript而不是bash;也就是说,选择是否反映在退出状态中?呼叫bash程序应该如何读取AppleScript段的结果?我回家后会添加详细信息和屏幕截图。太棒了,谢谢。我开始在Applescript中重写,但当然,这对我来说是全新的,所以所花的时间比我想要的要长一点。我认为版本0.0.1将使用BASH解决方案,我推动的下一个版本将是applescript版本。我回来了。。。忘了说这很有效。多谢!
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"}'
#!/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