如何使用 Mac (AppleScript) 读取文件并使用读取结果打开 Safari?
我需要根据读取结果打开多个Safari(或者打开选项卡即可)。
例如,如果一个文件有
http://a.com http://b.com
我想使用 Safari 打开 a.com 和 b.com。
我如何使用 Mac/AppleScript 做到这一点?
也许我可以运行 python 调用“open -a Safari”http://a.com",但我猜 AppleScript 就是这种工具工作。
I need to open multiple Safari (or open the tab is OK) based on the read result.
For example, if a file has
http://a.com http://b.com
I want to open a.com and b.com using Safari.
How can I do that with Mac/AppleScript?
Maybe I can run python calling "open -a Safari "http://a.com", but I guess AppleScript is the tool for this kind of job.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定 python,但这会读取一个文本文件并打开窗口,让我看看是否可以为您获取选项卡
将位置设置为(读取(选择带有提示“选择包含网址的文本文件”的文件))的段落
在某些位置与艾琳重复
如果 aline 的长度大于 0 那么
告诉应用程序“Safari”
在文档末尾创建新文档
将文档 1 的 URL 设置为 aline
结束告诉
结束如果
结束重复
编辑:
好的,这更好,它在单个窗口的选项卡中打开它们
新添加
这是基于regulus6633的帖子和我的帖子的另一种方式
not sure about python but this will read a text file and open windows let me see if I can get tabs for you though
set locations to paragraphs of (read (choose file with prompt "Pick text file containing urls"))
repeat with aline in locations
if length of aline is greater than 0 then
tell application "Safari"
make new document at end of documents
set URL of document 1 to aline
end tell
end if
end repeat
EDIT:
Ok this is better and it opens them in tabs of a single window
New Addtion
this is yet another way based on regulus6633's post in conjunction with mine
如果您希望它专门在 Safari 中打开链接,那么 mcgrailm 的解决方案很好。但是,第一部分不需要 Finder,因此请将该代码从 Finder 告诉块中取出。没有必要告诉 Finder 做 applescript 自己可以做的事情。
但是,您可能希望在用户的默认浏览器中打开链接。它可能是 Safari 或 Firefox 等。您可以使用“打开位置”命令来执行此操作。所以这样的东西可能就是你想要的......
If you want it to specifically open the links in Safari then mcgrailm's solution is good. However, you don't need the Finder for the first part so take that code out of the Finder tell block. There's no need to tell the Finder to do something that applescript can do itself.
However, you probably want to open the links in whatever browser is the user's default browser. It may be Safari or Firefox etc. You can do that with the "open location" command. So something like this is probably what you want...