swift - 在 macOS 中从浏览器获取当前 URL

标签 swift macos

有没有办法使用 Swift 从当前打开的浏览器(Chrome、Firefox 或 Safari)获取当前 URL?

最佳答案

你可以使用一些 Apple Script像这样:

set myURL to "No browser active"
set nameOfActiveApp to (path to frontmost application as text)
if "Safari" is in nameOfActiveApp then
    tell application "Safari"
        set myURL to the URL of the current tab of the front window
    end tell
else if "Chrome" is in nameOfActiveApp then
    tell application "Google Chrome"
        set myURL to the URL of the active tab of the front window
    end tell
end if

display dialog (myURL)

关于swift - 在 macOS 中从浏览器获取当前 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42369202/

相关文章:

ios - 获取结果 Controller 委托(delegate)在 swift 1.2/xcode 6.3 更新后未调用

macos - SMJobBless 仅适用于 kSMDomainSystemLaunchd,需要 kSMDomainUserLaunchd

macos - 使用brew构建libgit2静态库

iOS 8 Today Widget 显示空白几秒钟

swift - 自定义警报显示在空窗口而不是以前的 viewController

macos - 是否可以授予沙盒应用程序访问从 AppleScript 发送的文件的权限?

ios - 多个 NSThread 同步

macos - 从终端在 MAC OS 上安装 dmg 包

css - Angular 半径不起作用?

ios - 持续后台更新位置