【问题标题】:applescript droplet to insert text in safariapplescript droplet 在 Safari 中插入文本
【发布时间】:2014-04-16 10:40:52
【问题描述】:

我创建了一个可以读取文本文件并将内容提供给剪贴板的 droplet:

on open theFile
open for access theFile
set fileContents to (read theFile)
close access theFile
return fileContents
set the clipboard to fileContents
end open

但我正在寻找一些代码来从剪贴板中获取这些内容 并将其插入到 safari 最前面窗口的当前字段中。

为此,我发现了一些用于自动操作的代码 以某种方式模拟 cmd+v 的击键:

on run {input, parameters}
tell application "Safari"
    activate
    tell application "System Events"
        keystroke "v" using command down
    end tell
    return input
end tell
end run

我的问题是如何把这两件事放在一起。 最后,液滴应该以这种方式工作:

  • 在 droplet 上放置文本文件
  • 在最前面的 Safari 窗口的活动字段中插入文本文件的内容。

感谢帮助

【问题讨论】:

    标签: safari applescript


    【解决方案1】:

    这应该可以为您完成工作。

    我将代码击键设置为变量,这样您就不必弄乱剪贴板并冒着意外输入错误数据的风险。

    on open the_file
        set the_file_Contents to (read the_file)
        tell application "Safari"
            activate
            tell application "System Events"
                keystroke the_file_Contents
            end tell
        end tell
    end open
    

    如果您希望代码仍然使用剪贴板(对大文本文件更有效),代码应该如下所示。

    on open the_file
        set the clipboard to (read the_file)
        tell application "Safari"
            activate
            tell application "System Events"
                keystroke "v" using command down
            end tell
        end tell
    end open
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多