2014-02-13 45 views
0

我搜索了高和低,並找不到答案。如何使用Applescript從Chrome複製並粘貼網址?

如何將Chrome中的網址複製並粘貼到Excel中?

本質上,我有一個項目,我必須複製並粘貼到搜索引擎的值。我必須保存該搜索結果的網址。我不知道如何使用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 

末告訴

回答

0

劇本我自己似乎有點古怪,因爲你使用了大量不必要的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) 

但是:我強烈建議使用完整的可能性重新創建腳本(又名字典)的目標應用程序!只有使用香草蘋果,才能達到您的目標!