LoginSignup
0

More than 5 years have passed since last update.

AppleScriptでOSXファイヤウォールの受信接続許可ボタンを自動的に押す

Posted at

OSX Mavericksになってからなのか、Charles.appを立ち上げるたびに次のようなファイヤウォールの確認ダイアログが出るようになった。
A2924C56-FF0A-4AD4-98B1-037A688D465D.png

AppleScript等でCharlesでのログ取りなど自動化をするにあたって、許可ボタンを自動的に押す必要があったので調べた。次のようなAppleScriptを書くと、ダイアログ内のテキストに「Charles.app」があったときだけ、許可ボタンを押すことが出来る。

具体的には、このダイアログはUserNotificationCenterというプロセスが表示しているようなので、そのプロセスに対してAppleScriptを実行している。

tell application "System Events"
  -- ダイアログはUserNotificationCenterプロセスが表示しているので、まずはUserNotificationCenterプロセスの有無を確認
  if "UserNotificationCenter" is in (get name of processes whose background only is true) then
    tell process "UserNotificationCenter"
      tell window 1
        -- first static textは『アプリケーション"Charles.app"へのネットワーク……』という文字列を保持している
        if value of first static text contains "Charles.app" then
          click button "許可"
        end if
      end tell
    end tell
  end if
end tell

実装に当たって、以下のサイトを参考にした。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0