2017-08-01 68 views
0

此测试脚本是复制我的问题的确切场景。通过终端但不与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运行时,元素没有被检测到?

这是否与权限有关?

+0

这可能是有用的一些记录添加到脚本中才能看到什么错。您可以将此行添加到cron定义中:'* * * * * sleep 10; python /Users/user/Desktop/test.py >>/tmp/cron.log' –

+0

是的。我试着补充说。我越来越“切换是[]”。我确信cron正在触发。但是这里的问题是,为什么在通过cron运行时没有检测到ui元素? – srinath

回答

0

我想你每秒都在运行你的cron工作。您可以检查日期/tmp/test1.txt以确保它始终在重新创建。

我也想你也应该之前装入.profile,像这样:

30 14 * * * . .profile; python /Users/user/Desktop/test.py 
+0

我相信脚本正在执行。但不知道为什么它没有通过cron运行时检测到UI元素 – srinath

+0

而我没有bash配置文件。你建议保留在bash配置文件中? – srinath