[英]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.