簡體   English   中英

如何使用 Applescript 從 Chrome 復制和粘貼 URL?

[英]How do I copy and paste the URL from Chrome using Applescript?

我搜索了高低,找不到答案。

如何將 Chrome 中的 URL 復制並粘貼到 Excel 中?

本質上,我有一個項目在工作,我必須將值復制並粘貼到搜索引擎中。 我必須保存該搜索結果的 URL。 我不知道如何使用 Applescript 做到這一點。 這是我到目前為止的代碼。 我知道它不優雅,但我很感激任何幫助!


告訴應用程序“Microsoft Excel”激活

告訴應用程序“系統事件”

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

結束告訴

延遲 0.4

告訴應用程序“谷歌瀏覽器”激活

告訴應用程序“系統事件”

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

結束告訴

腳本本身似乎有點古怪,因為您使用了很多不必要的 UI 腳本。 這表示(對於您的腳本)解決方案是,您復制 url 並將其粘貼到瀏覽器中。 過了一會兒,您想讀取 url 並將其粘貼到初始 url 旁邊的單元格中。 您忘記在該步驟之前復制網址。 如果您使用keystroke "v" using command down粘貼,則剪貼板中僅存儲了初始 url。

如果您希望腳本以這種方式工作,則必須更改該行

get URL of active tab of first window as text

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

但是:我強烈建議您使用目標應用程序的全部可能性(又名字典)重新創建您的腳本! 您只能使用香草 Applescript 達到您的目標!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM