文本编辑和第三方应用程序之间的applescript复制粘贴不工作

文本编辑和第三方应用程序之间的applescript复制粘贴不工作,applescript,Applescript,我已经搜索了整个网站,找不到一个答案,为什么这段代码没有做我需要它做的事情。我有一个带有数字列表的文本编辑文档。我想一次复制一个数字,将该数字粘贴到url中特定位置的第三方应用程序中,然后点击该应用程序ui中的一些按钮。我需要对textedit文档中的每个数字重复此过程 这是我在研究applescript后得出的结论 tell application "TextEdit" to activate tell application "System Events" tell process

我已经搜索了整个网站,找不到一个答案,为什么这段代码没有做我需要它做的事情。我有一个带有数字列表的文本编辑文档。我想一次复制一个数字,将该数字粘贴到url中特定位置的第三方应用程序中,然后点击该应用程序ui中的一些按钮。我需要对textedit文档中的每个数字重复此过程

这是我在研究applescript后得出的结论

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
告诉应用程序“TextEdit”激活
告诉应用程序“系统事件”
告诉进程“文本编辑”
使用{shift down,command down}键代码124
使用“向下”命令击键“c”
钥匙代码125
结束语
结束语
延迟1.0
告诉应用程序“import.io”激活
告诉应用程序“系统事件”
告诉进程“import.io”
击键选项卡
击键选项卡
钥匙代码124
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
钥匙代码123
密码51
使用“向下”命令击键“v”
击键选项卡
钥匙代码76
结束语
结束语
--从弹出按钮中进行选择。
延迟2.231426
将timeoutSeconds设置为10.0
将uiScript设置为“单击应用程序进程”import.io“保存”窗口的弹出按钮1”
my doWithTimeout(uiScript,timeoutSeconds)
返回输入
终点
在doWithTimeout上(uiScript,timeoutSeconds)
将endDate设置为(当前日期)+timeoutSeconds
重复
尝试
运行脚本“告诉应用程序”“系统事件”
“&uiScript&”
结束讲述“
退出重复
关于错误消息
如果((当前日期)>结束日期),则
错误“不能”&uiScript
如果结束
结束尝试
结束重复
结束超时
--单击“”复选框。
延迟1.496275
将timeoutSeconds设置为10.0
将uiScript设置为“单击应用程序进程”import.io“保存”窗口的复选框1”
my doWithTimeout(uiScript,timeoutSeconds)
返回输入
--在文本字段中键入“数据”。
延迟7.290406
将timeoutSeconds设置为10.0
将uiScript设置为“单击应用程序进程导入的窗口“保存”的组2的组1的拆分器组1的拆分器组1的浏览器1的滚动区1的列表1的组17的文本字段1”
击键“数据”
击键“
告诉应用程序“系统事件”告诉进程“import.io”
使用“向下”命令击键“v”
结束语
my doWithTimeout(uiScript,timeoutSeconds)
返回输入
--单击“保存”按钮。
延迟1.475013
将timeoutSeconds设置为10.0
将uiScript设置为应用程序进程“import.io”的“保存”窗口的“单击UI元素”保存
my doWithTimeout(uiScript,timeoutSeconds)
返回输入
我的文本编辑文档的格式如下:
50
100
150
200
等
当我运行脚本时,它会对我的textedit文档执行以下操作:
50
50
100
150
200
等

知道这是怎么回事吗?我对这件事一无所知

在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脚本的缺点是不能更改应用程序界面。但在你的剧本中已经是这样了