2017-08-01 56 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