2017-02-21 6 views
-1

Swiftを使用して現在開いているブラウザ(Chrome、Firefox、Safari)から現在のURLを取得する方法はありますか?macOSのブラウザから現在のURLを取得

+0

?人々にあなたに仕事を依頼するだけではありません。あなたが試したこととうまくいかなかったことを教えてください。あなた自身を助けようと時間を割いたことを証明するために、明白な答えを私たちに提供しません。回答。 [Ask] –

+0

も参照してください。AppleScriptで行うこともできます。 –

+0

AppleScriptを使用した[this](http://stackoverflow.com/a/6111592)アプローチが見つかりました。しかし、私はそれをSwiftに適切に変換することはできませんでした。特にこの行 'NSString * result = [[NSString alloc] initWithCharacters:(unichar *)[data bytes]] length:[data length]/sizeof(unichar)];' – ttrs

答えて

1

あなたはこのようないくつかの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) 
関連する問題