简体   繁体   English

如何使用 Applescript 从 Chrome 复制和粘贴 URL?

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

I've searched high and low and cannot find the answer to this.我搜索了高低,找不到答案。

How do I copy and paste the URL from Chrome into Excel?如何将 Chrome 中的 URL 复制并粘贴到 Excel 中?

Essentially, I have a project at work where I have to copy and paste values into a search engine.本质上,我有一个项目在工作,我必须将值复制并粘贴到搜索引擎中。 I have to save the URL of the results from that search.我必须保存该搜索结果的 URL。 I don't know how to do this using Applescript.我不知道如何使用 Applescript 做到这一点。 This is the code I have so far.这是我到目前为止的代码。 I know it's not elegant, but I'd appreciate any help!我知道它不优雅,但我很感激任何帮助!


tell application "Microsoft Excel" to activate告诉应用程序“Microsoft Excel”激活

tell application "System Events"告诉应用程序“系统事件”

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

end tell结束告诉

delay 0.4延迟 0.4

tell application "Google Chrome" to activate告诉应用程序“谷歌浏览器”激活

tell application "System Events"告诉应用程序“系统事件”

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

end tell结束告诉

tell application "Microsoft Excel" to activate告诉应用程序“Microsoft Excel”激活

tell application "System Events"告诉应用程序“系统事件”

tell process "Microsoft Excel"


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

end tell结束告诉

the script itself seems a little bit quirky, because you use a lot of unnecessary UI scripting.脚本本身似乎有点古怪,因为您使用了很多不必要的 UI 脚本。 This said the solution (for your script) is, that you copy the url and paste it into the browser.这表示(对于您的脚本)解决方案是,您复制 url 并将其粘贴到浏览器中。 After a while you want to read the url and paste it into the cell next to the initial url.过了一会儿,您想读取 url 并将其粘贴到初始 url 旁边的单元格中。 You forgot to copy the url before that step.您忘记在该步骤之前复制网址。 If you paste using keystroke "v" using command down there is only the initial url stored in the clipboard.如果您使用keystroke "v" using command down粘贴,则剪贴板中仅存储了初始 url。

If you want the script working in that way you have to change the line如果您希望脚本以这种方式工作,则必须更改该行

get URL of active tab of first window as text

to

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

But: I strongly recommend to recreate your script using the full possibilities (aka dictionaries) of the targeted applications!但是:我强烈建议您使用目标应用程序的全部可能性(又名字典)重新创建您的脚本! You can reach your aim using vanilla applescript only!您只能使用香草 Applescript 达到您的目标!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用VBA从URL复制和粘贴 - Copy and Paste from a URL using VBA 如何将数据从pdf复制并粘贴到excel? - How do I copy and paste data from pdf to excel? 如何设置复制和粘贴目的地? - How do i set copy and paste destination? 如何使用 Powershell 从 excel 中的一个工作簿的特定单元格复制信息并将其粘贴到另一个工作簿的特定单元格? - How do I copy info from a specific cell from one workbook in excel and paste it to a specific cell to another workbook using Powershell? 如何使用Applescript在Excel中粘贴特殊内容? - How to paste special in Excel using Applescript? 如何将数据复制并粘贴到我使用 for 循环在 VBA 中创建的工作表中? - How do i copy and paste data to worksheets that i created in VBA using for loop? 如何使用excel VBA以特定方式复制和粘贴单元格,然后删除某些行? - How do I copy and paste cells and then delete certain rows in a specific way using excel VBA? 如何将列复制并粘贴到从另一行开始的其他工作簿中? 使用VBA - How do I Copy and paste columns into a different workbook starting at a different row? Using VBA 如何使用excel VBA将excel选项卡的格式复制并粘贴到除所选工作表以外的其他选项卡上 - How do I copy and paste formatting of excel tab to other tabs except a selected sheet using excel VBA 如何使用 VBA 将值和格式复制并粘贴到新工作表 - How do I copy and paste values and formats to a new worksheet using VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM