【问题标题】:How to get all open URL in every tab of every Window in Safari?如何在 Safari 中的每个窗口的每个选项卡中获取所有打开的 URL?
【发布时间】:2016-09-05 09:00:56
【问题描述】:

我正在使用 NSAppleScript 告诉 Safari 返回所有打开的标签的 URL,如下所示:

let script = NSAppleScript.init(source: "tell application \"Safari\" to get URL of every tab of every window")
var errorInfo: NSDictionary?
let eventDescriptor:NSAppleEventDescriptor = (script?.executeAndReturnError(&errorInfo))!
print(eventDescriptor.stringValue)

以上返回零。告诉返回当前 URL 确实有效。

"tell application \"Safari\" to return URL of front document as string"

如何在每个窗口的每个选项卡中获取所有打开的 URL?

【问题讨论】:

    标签: swift macos cocoa safari applescript


    【解决方案1】:

    结果将是一个表示字符串列表列表的 NSDescriptor。无论是你:

    1. 在返回之前将列表强制转换为 AppleScript 中的字符串,使用合适的文本项分隔符,然后您可以将字符串拆分为 Swift 中的字符串列表(作弊),
    2. 使用几个嵌套循环自己解压列表描述符(乏味),或者
    3. 放弃 NSAppleScript 并改用 AppleScript-ObjC bridge(设置起来有点繁琐,但到目前为止是最简单且最实用的)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-10
      • 2018-06-08
      • 1970-01-01
      • 2014-04-15
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多