我在这个网站上搜索过,找不到为什么这段代码不能做我需要做的事情的答案。我有一个带有数字列表的textedit doc。我想一次复制1个数字,将该数字粘贴到url中特定位置的第三方应用程序中,然后点击该应用程序的ui中的某些按钮。我需要这个过程重复textedit文档中的每个单独的数字。
以下是我研究过Applecript后得出的结论。
tell application "TextEdit" to activate
tell application "System Events"
tell process "TextEdit"
key code 124 using {shift down, command down}
keystroke "c" using command down
key code 125
end tell
end tell
delay 1.0
tell application "import.io" to activate
tell application "System Events"
tell process "import.io"
keystroke tab
keystroke tab
key code 124
key code 123
key code 123
key code 123
key code 123
key code 123
key code 123
key code 123
key code 123
key code 123
key code 123
key code 123
key code 123
key code 123
key code 123
key code 51
keystroke "v" using command down
keystroke tab
key code 76
end tell
end tell
-- Make a selection from the popupbutton.
delay 2.231426
set timeoutSeconds to 10.0
set uiScript to "click pop up button 1 of window \"Save\" of application process \"import.io\""
my doWithTimeout(uiScript, timeoutSeconds)
return input
end run
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout
-- Click the “<fill in title>” checkbox.
delay 1.496275
set timeoutSeconds to 10.0
set uiScript to "click checkbox 1 of window \"Save\" of application process \"import.io\""
my doWithTimeout(uiScript, timeoutSeconds)
return input
-- Type “Data” into the text field.
delay 7.290406
set timeoutSeconds to 10.0
set uiScript to "click text field 1 of group 17 of list 1 of scroll area 1 of scroll area 1 of browser 1 of splitter group 1 of splitter group 1 of group 2 of window \"Save\" of application process \"import.io\""
keystroke "Data"
keystroke "."
tell application "System Events" to tell process "import.io"
keystroke "v" using command down
end tell
my doWithTimeout(uiScript, timeoutSeconds)
return input
-- Click the “Save” button.
delay 1.475013
set timeoutSeconds to 10.0
set uiScript to "click UI Element \"Save\" of window \"Save\" of application process \"import.io\""
my doWithTimeout(uiScript, timeoutSeconds)
return input
my textedit document is formatted like this:
50
100
150
200
etc
When I run the script this is what it does to my textedit document:
50
50
100
150
200
etc
知道这里发生了什么吗?我无法做出正面或反面。
答案 0 :(得分:0)
在TextEdit文件中查找结果,首先必须开始简化textEdit复制部分。我假设TextEdit文档已经打开。
下面的脚本简化了复制部分:
tell application "TextEdit"
activate
set myNumbers to every paragraph of front document
end tell
repeat with aNumber in myNumbers -- loop through each number
set the clipboard to aNumber
-- insert here the paste instructions in your third party application
end repeat
在“设置剪贴板...”指令后,必须在循环中插入有关粘贴的说明,该说明用数字填充剪贴板。
我无法帮助您获取粘贴部分,因为我不知道您的第三方应用程序,但是,您的程序在doWithTimeout例程中调用其他脚本似乎不是非常干净和高效。
如果此第三方应用程序不可编写脚本,至少您可能必须通过GUI脚本或java(如果基于Java的应用程序)。 例如,不要将所有关键箭头移动到正确的输入单元格,而是尝试通过其GUI属性直接寻址该单元格。
对于复选框,您也可以使用GUI点击功能。
GUI脚本的缺点是不能更改应用程序接口。但是你的脚本就是这种情况。