20260512

[AppleScript] システム設定>プライバシーとセキュリティ>プライバシーとセキュリティ>フルディスクアクセスを開く

[AppleScript] システム設定>プライバシーとセキュリティ>プライバシーとセキュリティ>フルディスクアクセスを開く

NOTE記事一覧ですnote.com

【スクリプトエディタで開く】 |

2_フルディスクアクセスを開く.applescript.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004
005システム設定の
006プライバシーとセキュリティ>プライバシーとセキュリティ>フルディスクアクセス
007
008開きます
009
010com.cocolog-nifty.quicktimer.icefloe *)
011----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
012use AppleScript version "2.8"
013use framework "Foundation"
014use framework "AppKit"
015use framework "UniformTypeIdentifiers"
016use scripting additions
017property refMe : a reference to current application
018set strBundleID to ("com.apple.systempreferences") as text
019###URLにする
020set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
021###スキーム
022ocidURLComponents's setScheme:("x-apple.systempreferences")
023###パネルIDをパスにセット
024ocidURLComponents's setPath:("com.apple.settings.PrivacySecurity.extension")
025###アンカーをクエリーとして追加
026ocidURLComponents's setQuery:("Privacy_AllFiles")
027set ocidOpenAppURL to ocidURLComponents's |URL|
028set strOpenAppURL to ocidOpenAppURL's absoluteString() as text
029###ワークスペースで開く
030set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
031set boolDone to appShardWorkspace's openURL:(ocidOpenAppURL)
032log boolDone
033if boolDone is false then
034   tell application id "com.apple.systempreferences"
035      activate
036      set miniaturized of the settings window to false
037   end tell
038   tell application id "com.apple.finder"
039      open location "x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_AllFiles"
040   end tell
041   tell application id "com.apple.systempreferences"
042      reveal anchor "Privacy_AllFiles" of pane id "com.apple.settings.PrivacySecurity.extension"
043   end tell
044   tell application id "com.apple.systempreferences" to activate
045end if
046###開くのを待つ
047repeat 10 times
048   tell application id "com.apple.systempreferences"
049      set boolFrontMost to frontmost as boolean
050   end tell
051   if boolFrontMost is true then
052      delay 1
053      exit repeat
054   else
055      tell application id "com.apple.systempreferences" to activate
056      delay 0.5
057   end if
058end repeat
059###パネルを確認して
060repeat 10 times
061   tell application id "com.apple.systempreferences"
062      activate
063      tell current pane
064         set strPaneID to id
065      end tell
066   end tell
067   if strPaneID is "com.apple.systempreferences.GeneralSettings" then
068      delay 0.5
069   else if strPaneID is "com.apple.settings.PrivacySecurity.extension" then
070      exit repeat
071   end if
072end repeat
073###アンカーを再指定
074tell application "System Settings"
075   tell pane id "com.apple.settings.PrivacySecurity.extension"
076      tell anchor "Privacy_AllFiles"
077         try
078            reveal
079         end try
080      end tell
081   end tell
082end tell
083return 0
AppleScriptで生成しました