2013-06-03 56 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" 

这是非常微妙的,我已经看到了,但之前我现在更好地实现它是什么。非常感谢!