【问题标题】:How do I copy and paste the URL from Chrome using Applescript?如何使用 Applescript 从 Chrome 复制和粘贴 URL?
【发布时间】:2014-03-12 22:55:39
【问题描述】:

我找遍了高低,找不到答案。

如何将 URL 从 Chrome 复制并粘贴到 Excel 中?

基本上,我有一个工作项目,我必须将值复制并粘贴到搜索引擎中。我必须保存该搜索结果的 URL。我不知道如何使用 Applescript 来做到这一点。这是我到目前为止的代码。我知道这并不优雅,但我将不胜感激!


告诉应用程序“Microsoft Excel”激活

告诉应用程序“系统事件”

tell process "Microsoft Excel"
    keystroke "c" using command down
end tell

说完

延迟 0.4

告诉应用程序“Google Chrome”激活

告诉应用程序“系统事件”

tell process "Google Chrome"
    keystroke "a" using command down
    keystroke "v" using command down
end tell
delay 0.5
tell application "System Events"
    tell process "Google Chrome"
        keystroke return
    end tell
end tell
delay 5.0
tell application "Google Chrome"

    get URL of active tab of first window as text

end tell
delay 5.0
tell application "System Events" to keystroke "w" using command down

说完

告诉应用程序“Microsoft Excel”激活

告诉应用程序“系统事件”

tell process "Microsoft Excel"


    keystroke tab
    keystroke "v" using command down
    keystroke down
    keystroke left
end tell

说完

【问题讨论】:

    标签: excel macos google-chrome applescript


    【解决方案1】:

    脚本本身似乎有点古怪,因为您使用了很多不必要的 UI 脚本。这表示解决方案(对于您的脚本)是,您复制 url 并将其粘贴到浏览器中。过了一会儿,您想读取 url 并将其粘贴到初始 url 旁边的单元格中。您忘记在该步骤之前复制 url。如果您使用keystroke "v" using command down 粘贴,则剪贴板中仅存储初始网址。

    如果您希望脚本以这种方式工作,则必须更改行

    get URL of active tab of first window as text
    

    set the clipboard to (URL of active tab of first window as text)
    

    但是:我强烈建议您使用目标应用程序的全部可能性(又名字典)重新创建您的脚本!您只能使用香草 AppleScript 来达到您的目标!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 2023-01-20
      • 2014-01-02
      • 2018-03-23
      相关资源
      最近更新 更多