【问题标题】:applescript copy paste between textedit and 3rd party application not workingtextedit和第3方应用程序之间的applescript复制粘贴不起作用
【发布时间】:2016-02-17 14:52:12
【问题描述】:

我在整个网站上进行了搜索,但无法找到为什么这段代码没有做我需要做的事情的答案。我有一个带有数字列表的文本编辑文档。我想一次复制 1 个数字,将该数字粘贴到 url 中特定位置的 3rd 方应用程序中,然后点击该应用程序的 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

知道这里发生了什么吗?我无法对它做出正面或反面。

【问题讨论】:

    标签: applescript


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-08
      • 2020-05-01
      • 2019-01-16
      • 1970-01-01
      • 2017-12-23
      • 1970-01-01
      相关资源
      最近更新 更多