2013-06-03 50 views
0

編輯:我試圖從使用AppleScript的Web代理調試應用程序Charles(http://www.charlesproxy.com/)保存會話文件。基本上,我選擇「導出」,輸入臨時名稱,然後保存。但是,在單擊組合框2(即「格式」區域)後,嘗試單擊彈出按鈕「XML會話文件(.xml)」後,Applescript編輯器會拋出一個錯誤,指出它找不到它。Charles和AppleScript(在輔助功能檢查器中缺失值)

目前我用下面的代碼入侵它,但由於某些原因,它只能在Applescript編輯器中工作,有時在Terminal /我的代碼中工作,特別是當我在同一時間執行其他操作時。

tell application "Charles" 
    activate 
end tell 

tell application "System Events" 
    tell process "Charles" 
     tell menu bar 1 
      click menu bar item "File" 
      tell menu "File" 
       click menu item "Export..." 
      end tell 
     end tell 
     tell window "Save" 
      keystroke "tempCharles" 
      delay 0.5 
      click combo box 2 
      delay 0.5 
      key code 125 -- down arrow 
      delay 0.2 
      key code 125 
      delay 0.2 
      key code 125 
      delay 0.2 
      key code 125 
      delay 0.2 
      keystroke return 
      delay 0.4 
      keystroke return 
      delay 0.4 
      keystroke return 
     end tell 
    end tell 
end tell 

我想我的代碼看起來像這樣

tell window "Save" 
     keystroke "tempCharles.xml" 
     delay 3 
     click combo box 2 
     tell combo box 2 
      click pop up button "XML Session File (.xml)" 
     end tell 
     click button "Save" 
    end tell 

任何黑客是好的了。在發佈之前,嘗試在終端上運行「osascript」以檢查它是否通過AppleScript編輯器工作。

回答

0

set value of text field 1 of window 1似乎沒有任何工作,但你可以嘗試只使用keystroke

delay 0.5 -- time to release modifier keys if the script is run with a shortcut like cmd-R 
tell application "System Events" to tell process "Charles" 
    set frontmost to true 
    click menu item "Save..." of menu 1 of menu bar item "File" of menu bar 1 
    keystroke "templog" & return 
end tell 
0

沒錯奏效!我只是說

-- Got rid of the "set text" line 
keystroke return 
delay 1 
click button "Save" 

這是非常微妙的,我已經看到了,但之前我現在更好地實現它是什麼。非常感謝!