有没有办法使用 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/