此测试脚本是复制我的问题的确切场景。通过终端但不与cron通信的脚本
import atomac, time
noront = atomac.getAppRefByBundleId(BUNDLE_ID)
noront.activate()
time.sleep(5)
ax = {'AXRole' : 'AXButton'}
toggle = noront.findAllR(**ax)
print "Toggle is ", toggle
with open("/tmp/test1.txt", 'w') as fp:
fp.write(str(toggle))
当我运行在终端这个剧本我得到的输出
python /Users/user/Desktop/test.py
运行后,当我做 猫/tmp/test1.txt
[<atomac.AXClasses.NativeUIElement AXButton u'I agree'>, <atomac.AXClasses.NativeUIElement AXButton u'I Accept'>, <atomac.AXClasses.NativeUIElement AXButton u'Pr P'>, <atomac.AXClasses.NativeUIElement AXButton None>, <atomac.AXClasses.NativeUIElement AXButton None>, <atomac.AXClasses.NativeUIElement AXButton None>]
然而,我加入同样的cron条目。
* * * * * sleep 10; python /Users/user/Desktop/test.py
运行后,当我做
cat /tmp/test1.txt
[]
返回空集。有人能帮助我为什么当我通过cron运行时,元素没有被检测到?
这是否与权限有关?
这可能是有用的一些记录添加到脚本中才能看到什么错。您可以将此行添加到cron定义中:'* * * * * sleep 10; python /Users/user/Desktop/test.py >>/tmp/cron.log' –
是的。我试着补充说。我越来越“切换是[]”。我确信cron正在触发。但是这里的问题是,为什么在通过cron运行时没有检测到ui元素? – srinath