如何在safari中打开一个新窗口,然后使用苹果脚本在该窗口中打开多个选项卡和不同的网址?如何用apple脚本在Safari中打开一个新窗口和多个URL?
5
A
回答
7
建立在Safari新窗口的方式是使用make new document
命令:
make new document at end of documents with properties {URL:the_url}
这将创建一个新的窗口,一个标签指向the_url
,使该窗口最前面。请注意,make new window at end of windows
不起作用,只是出现“AppleEvent处理程序失败”的错误。
同样,创建一个窗口w
内一个新的标签,你可以使用make new tab
:
make new tab at end of tabs of w with properties {URL:the_url}
这将在标签的列表的末尾创建窗口w
一个新的标签;此选项卡将指向the_url
,而其不会是是当前选项卡。相反的明确说法tabs of w
,你也可以使用一个tell w
块:
tell w
make new tab at end of tabs with properties {URL:the_url}
end tell
这样,tabs
隐指tabs of w
。
把这个都在一起,我们得到下面的脚本。给定the_urls
中的URL列表,它将在新窗口中打开所有这些URL;如果the_urls
为空,它将打开一个带有空白选项卡的窗口。
property the_urls : {¬
"http://stackoverflow.com", ¬
"http://tex.stackexchange.com", ¬
"http://apple.stackexchange.com"}
tell application "Safari"
if the_urls = {} then
-- If you don't want to open a new window for an empty list, replace the
-- following line with just "return"
set {first_url, rest_urls} to {"", {}}
else
-- `item 1 of ...` gets the first item of a list, `rest of ...` gets
-- everything after the first item of a list. We treat the two
-- differently because the first item must be placed in a new window, but
-- everything else must be placed in a new tab.
set {first_url, rest_urls} to {item 1 of the_urls, rest of the_urls}
end if
make new document at end of documents with properties {URL:first_url}
tell window 1
repeat with the_url in rest_urls
make new tab at end of tabs with properties {URL:the_url}
end repeat
end tell
end tell
1
tell application "Safari"
activate
set the URL of document 1 to "http://www.XXXXXXX.com"
my new_tab()
set the URL of document 1 to "http://www.XXXXXX.com"
end tell
on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
«event prcsclic» «class menI» "New Tab" of «class menE» "File" of «class mbar» 1
end tell
end tell
end new_tab
更换X与任何你想要的网站和不断重复的代码(我new_tab(),并设置URL ...线)为每个想有打开的页面。 参考this page. 纠正我,如果这不是你在说什么。在Pugmatt的回答
+0
感谢您的回复,Pugmatt。它接近我想要的。你的脚本在现有的Safari窗口中打开url - 我想在新窗口中打开。 – sevens 2012-07-29 06:20:13
0
基地我得到了以下工作...
on run {input, parameters}
tell application "Safari"
activate
make new document with properties {URL:"http://www.apple.com"}
my new_tab()
set the URL of document 1 to "http://www.example.com"
end tell
end run
on new_tab()
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
«event prcsclic» «class menI» "New Tab" of «class menE» "File" of «class mbar» 1
end tell
end tell
end new_tab
我不知道这是不是你这个最有效的方式。
相关问题
- 1. 在自己窗口中使用Java脚本打开一个URL
- 2. 如何在新窗口中打开一个URL不在新窗口中
- 3. 如何使用ScriptingBridge通知Safari在新窗口中打开URL?
- 4. 在Vim-embedded python脚本中打开一个新窗口
- 5. 在批处理脚本中打开一个新的CMD窗口
- 6. 如何关闭cmd窗口并打开一个新窗口来继续脚本
- 7. 打开一个新窗口
- 8. QT:如何打开一个新窗口
- 9. 在Silverlight中打开一个新窗口
- 10. 在asp.net中打开一个新窗口
- 11. 在PyGame中打开一个新窗口?
- 12. 如何在另一个窗口中检查打开的URL?
- 13. 用asp.net打开一个新窗口
- 14. 使用MVC打开一个新窗口
- 15. 用pygame打开一个新窗口
- 16. 使用PHP打开一个新窗口
- 17. 在safari中打开多个弹出式窗口11
- 18. 如何打开不在同一个新窗口中的新窗口?
- 19. 如何在5秒后使用java脚本打开新窗口
- 20. iscroll链接打开一个新的Safari浏览器窗口?
- 21. jQuery - >在窗口中打开一个新的小窗口
- 22. 如何在JavaScript中的同一个窗口中打开一个URL?
- 23. 如何在项目中打开另一个窗口(Xcode窗口)?
- 24. 在新窗口中打开URL Java
- 25. 如何从一个窗口打开一个窗口
- 26. 基本的Javascript问题:如何打开一个新窗口?
- 27. 如何打开多个灯箱窗口
- 28. 一个网格内打开URL在新的浏览器窗口
- 29. 如何在aspnet中打开一个新窗口
- 30. 如何在pyside中打开一个新窗口
感谢您的补充解释,安塔尔。有用! – sevens 2012-07-29 15:26:34