System Settings

EnableTilingByEdgeDrag to false (disable TilingByEdgeDrag)ウィンドウを画面端にドラッグすると実行されるタイル表示を無効化


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
005use AppleScript version "2.8"
006use framework "Foundation"
007use framework "AppKit"
008use framework "UniformTypeIdentifiers"
009use scripting additions
010property refMe : a reference to current application
011
012set appFileManager to refMe's NSFileManager's defaultManager()
013set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
014set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
015#
016set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.WindowManager.plist") isDirectory:(false)
017#
018set ocidReadPlist to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL)
019#
020set boolEdgeDrag to (ocidReadPlist's valueForKey:("EnableTilingByEdgeDrag")) as boolean
021log boolEdgeDrag
022if boolEdgeDrag is (true) then
023  set ocidFalse to (refMe's NSNumber's numberWithBool:(false))
024  ocidReadPlist's setObject:(ocidFalse) forKey:("EnableTilingByEdgeDrag")
025  set listDone to ocidReadPlist's writeToURL:(ocidPlistFilePathURL) |error| :(reference)
026  if (item 2 of listDone) ≠ (missing value) then
027    set strErrorNO to (item 2 of listDone)'s code() as text
028    set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
029    refMe's NSLog("■:" & strErrorNO & strErrorMes)
030    return "エラーしました" & strErrorNO & strErrorMes
031  end if
032end if
033try
034  do shell script ("/bin/zsh -c '/usr/bin/killall cfprefsd'")
035end try
036try
037  tell application id "com.apple.WindowManager" to launch
038end try
039try
040  do shell script ("/bin/zsh -c '/usr/bin/killall cfprefsd'")
041end try
042set strBundleID to "com.apple.systempreferences" as text
043###URLにする
044set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
045###スキーム
046ocidURLComponents's setScheme:("x-apple.systempreferences")
047###パネルIDをパスにセット
048ocidURLComponents's setPath:("com.apple.Desktop-Settings.extension")
049###アンカーをクエリーとして追加
050ocidURLComponents's setQuery:("Windows")
051set ocidOpenAppURL to ocidURLComponents's |URL|
052set strOpenAppURL to ocidOpenAppURL's absoluteString() as text
053###ワークスペースで開く
054set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
055set boolDone to appShardWorkspace's openURL:(ocidOpenAppURL)
056if boolDone is false then
057  tell application id "com.apple.systempreferences"
058    activate
059    set miniaturized of the settings window to false
060  end tell
061  tell application id "com.apple.finder"
062    open location "x-apple.systempreferences:com.apple.Desktop-Settings.extension?Windows"
063  end tell
064  tell application id "com.apple.systempreferences"
065    reveal anchor "Windows" of pane id "com.apple.Desktop-Settings.extension"
066  end tell
067  tell application id "com.apple.systempreferences" to activate
068end if
069return
AppleScriptで生成しました

|

システム設定をオープンさせるスクリプトの作成補助v5 (macOS14.5でreveal anchorの位置がずれるのに対応)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#システム設定オープン用のスクリプト作成補助 v5
004# アンカーのないタイプのパネルに対応した
005# 作成されるスクリプトにウィンドウの最小化を解除する手順を入れた
006# macOS14でreveal anchor の位置がずれるのに対応した
007#com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use framework "UniformTypeIdentifiers"
013use scripting additions
014
015property refMe : a reference to current application
016
017set strBundleID to "com.apple.systempreferences" as text
018
019############################
020###【1】システム設定の起動を確定させる
021set ocidRunAppArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
022if (count of ocidRunAppArray) ≠ 0 then
023  log "起動中です"
024  tell application id strBundleID to activate
025else
026  ####ゾンビ対策終了させてから処理させる
027  tell application id strBundleID
028    set numCntWindow to (count of every window) as integer
029  end tell
030  if numCntWindow = 0 then
031    tell application id strBundleID to quit
032  else
033    tell application id strBundleID
034      close (every window)
035      quit
036    end tell
037  end if
038  ####半ゾンビ化対策
039  set ocidRunningApplication to refMe's NSRunningApplication
040  set ocidAppArray to ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
041  repeat with itemAppArray in ocidAppArray
042    itemAppArray's terminate
043  end repeat
044  ###システム設定を起動させる
045  try
046    tell application id strBundleID to activate
047  on error
048    tell application "System Settings" to activate
049  end try
050  ###起動待ち
051  tell application id strBundleID
052    ###起動確認 最大10秒
053    repeat 10 times
054      activate
055      set boolFrontMost to frontmost as boolean
056      log boolFrontMost
057      if boolFrontMost is true then
058        ###魔法の1秒
059        delay 0.5
060        exit repeat
061      else
062        delay 0.5
063      end if
064    end repeat
065  end tell
066end if
067delay 3
068############################
069###【2】全てのパネルのIDを取得
070tell application id "com.apple.systempreferences"
071  set listPanelID to (id of every pane) as list
072end tell
073
074############################
075###【A】正順レコード
076set ocidPaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
077###【B】逆順レコード
078set ocidReversePaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
079###【3】1で取得したリストの数だけ繰り返し
080repeat with itemPanelID in listPanelID
081  set strPanelID to itemPanelID as text
082  tell application "System Settings"
083    set strPanelName to (name of pane id strPanelID) as text
084  end tell
085  ###【A】正順レコード
086  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelName) forKey:(strPanelID))
087  (ocidPaneDict's addEntriesFromDictionary:(ocidItemDict))
088  ###【B】逆順レコード
089  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelID) forKey:(strPanelName))
090  (ocidReversePaneDict's addEntriesFromDictionary:(ocidItemDict))
091end repeat
092
093############################
094###【4】ダイアログ用に正順レコードのLISTを作る
095set ocidAllValueArray to ocidPaneDict's allValues()
096##ソートしておく
097set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(true) selector:("localizedStandardCompare:")
098set ocidDescriptorArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
099ocidDescriptorArray's addObject:(ocidDescriptor)
100set ocidSortedKey to (ocidAllValueArray's sortedArrayUsingDescriptors:(ocidDescriptorArray))
101set listAllValueArray to ocidSortedKey as list
102############################
103###【5】ダイアログ  パネル
104set strName to (name of current application) as text
105if strName is "osascript" then
106  tell application "Finder" to activate
107else
108  tell current application to activate
109end if
110try
111  set listResponse to (choose from list listAllValueArray with title "選んでください" with prompt "選択したパネルを開きます" default items (item 1 of listAllValueArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
112on error
113  log "エラーしました"
114  return "エラーしました"
115end try
116if (item 1 of listResponse) is false then
117  return "キャンセルしました"
118else
119  set strResponse to (item 1 of listResponse) as text
120end if
121log strResponse
122############################
123###【6】戻り値を逆順リストで検索してパネルIDを取得
124set ocidPaneID to ocidReversePaneDict's valueForKey:(strResponse)
125set strPaneID to ocidPaneID as text
126log strPaneID
127
128############################
129###【7】アンカーの値の取得
130tell application "System Settings"
131  set listPaneAnchor to (name of anchors of pane strResponse) as list
132  log listPaneAnchor
133end tell
134###【7−1】一般選択時のみアンカーが無い
135if strResponse is "一般" then
136  set listPaneAnchor to {"Main"} as list
137else if listPaneAnchor is {} then
138  set listPaneAnchor to {""} as list
139  #
140  set appFileManager to refMe's NSFileManager's defaultManager()
141  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSLocalDomainMask))
142  set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
143  set ocidChkDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("PreferencePanes") isDirectory:(true)
144  #
145  set ocidOption to (refMe's NSDirectoryEnumerationSkipsSubdirectoryDescendants)
146  set ocidPropertieArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
147  ocidPropertieArray's addObject:(refMe's NSURLPathKey)
148  ocidPropertieArray's addObject:(refMe's NSURLNameKey)
149  set listResponse to appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:{} options:(ocidOption) |error| :(reference)
150  set ocidFilePathURLArray to (item 1 of listResponse)
151  repeat with itemFilePathURL in ocidFilePathURLArray
152    set ocidPlistFilePathURL to (itemFilePathURL's URLByAppendingPathComponent:("Contents/Info.plist"))
153    set listResponse to (refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error| :(reference))
154    set ocidPlistData to (item 1 of listResponse)
155    set strGetBundleID to (ocidPlistData's valueForKey:("CFBundleIdentifier")) as text
156    if strGetBundleID is strPaneID then
157      set ocidPaneURL to itemFilePathURL
158      set strFilePath to (itemFilePathURL's |path|()) as text
159    end if
160  end repeat
161end if
162
163############################
164###【8】ダイアログ アンカー
165set strName to (name of current application) as text
166if strName is "osascript" then
167  tell application "Finder" to activate
168else
169  tell current application to activate
170end if
171try
172  set listResponse to (choose from list listPaneAnchor with title "選んでください" with prompt "選択したアンカーを開きます" default items (item 1 of listPaneAnchor) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
173on error
174  log "エラーしました"
175  return "エラーしました"
176end try
177if (item 1 of listResponse) is false then
178  return "キャンセルしました"
179else
180  set strPaneAnchor to (item 1 of listResponse) as text
181end if
182log strPaneAnchor
183
184
185############################
186###【9】URLにする
187set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
188###スキーム
189ocidURLComponents's setScheme:("x-apple.systempreferences")
190###パネルIDをパスにセット
191ocidURLComponents's setPath:(ocidPaneID)
192###アンカーをクエリーとして追加
193ocidURLComponents's setQuery:(strPaneAnchor)
194set ocidOpenAppURL to ocidURLComponents's |URL|
195set strOpenAppURL to ocidOpenAppURL's absoluteString() as text
196log strOpenAppURL
197
198############################
199###【10】ワークスペースで開く
200###ファイルURLとパネルのURLをArrayにしておく
201set ocidOpenUrlArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
202ocidOpenUrlArray's insertObject:(ocidOpenAppURL) atIndex:0
203###FinderでURLを開くのでFinderのURLを用意
204set strBundleID to "com.apple.finder" as text
205set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
206set ocidAppPathURL to appShardWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID)
207###NSWorkspaceで開く
208set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration()
209ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true)
210ocidOpenConfig's setAllowsRunningApplicationSubstitution:(refMe's NSNumber's numberWithBool:true)
211appShardWorkspace's openURLs:(ocidOpenUrlArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)
212
213####システム設定が前面に来るまで待つ
214repeat 20 times
215  set boolFrontMost to frontmost of application id "com.apple.systempreferences"
216  if boolFrontMost is false then
217    tell application id "com.apple.systempreferences" to activate
218  else
219    exit repeat
220  end if
221  delay 0.2
222end repeat
223
224
225#################################
226###【11】ダイアログ用に値を用意
227if listPaneAnchor is {""} then
228  set strScript to ("#! /usr/bin/env osascript\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\n#\n# com.cocolog-nifty.quicktimer.icefloe\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\nuse AppleScript version \"2.8\"\nuse framework \"Foundation\"\nuse framework \"AppKit\"\nuse scripting additions\n\nproperty refMe : a reference to current application\n\nset strFilePath to (\"" & strFilePath & "\") as text\nset ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)\nset ocidFilePath to ocidFilePathStr's stringByStandardizingPath()\nset ocidSystemPreferencesURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)\n##\nset ocidWorkspace to refMe's NSWorkspace's sharedWorkspace()\nset boolDone to ocidWorkspace's openURL:(ocidSystemPreferencesURL)\nif boolDone is false then\n\tset aliasFilePath to (POSIX file strFilePath) as alias\n\ttell application \"Finder\"\n\t\topen location aliasFilePath\n\tend tell\nend if\nreturn") as text
229else
230  set strScript to ("#! /usr/bin/env osascript\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\n#com.cocolog-nifty.quicktimer.icefloe\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\nuse AppleScript version \"2.8\"\nuse framework \"Foundation\"\nuse framework \"AppKit\"\nuse framework \"UniformTypeIdentifiers\"\nuse scripting additions\nproperty refMe : a reference to current application\nset strBundleID to \"com.apple.systempreferences\" as text\n###URLにする\nset ocidURLComponents to refMe's NSURLComponents's alloc()'s init()\n###スキーム\nocidURLComponents's setScheme:(\"x-apple.systempreferences\")\n###パネルIDをパスにセット\nocidURLComponents's setPath:(\"" & strPaneID & "\")\n###アンカーをクエリーとして追加\nocidURLComponents's setQuery:(\"" & strPaneAnchor & "\")\nset ocidOpenAppURL to ocidURLComponents's |URL|\nset strOpenAppURL to ocidOpenAppURL's absoluteString() as text\n###ワークスペースで開く\nset appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()\nset boolDone to appShardWorkspace's openURL:(ocidOpenAppURL)\nlog boolDone\nif boolDone is false then\ntell application id \"com.apple.systempreferences\"\nactivate\nset miniaturized of the settings window to false\nend tell\ntell application id \"com.apple.finder\"\nopen location \"" & strOpenAppURL & "\"\nend tell\ntell application id \"com.apple.systempreferences\"\nreveal anchor \"" & strPaneAnchor & "\" of pane id \"" & strPaneID & "\"\nend tell\ntell application id \"com.apple.systempreferences\" to activate\nend if\nreturn\n") as text
231end if
232#################################
233###【12】戻り値ダイアログ
234set strName to (name of current application) as text
235log strName
236if strName is "osascript" then
237  repeat 20 times
238    set boolFrontMost to frontmost of application "Finder"
239    if boolFrontMost is false then
240      tell application "Finder" to activate
241    else
242      exit repeat
243    end if
244    delay 0.2
245  end repeat
246else
247  repeat 5 times
248    set boolFrontMost to frontmost of application "Script Editor"
249    log boolFrontMost
250    if boolFrontMost is false then
251      tell current application to activate
252    else
253      exit repeat
254    end if
255    delay 0.2
256  end repeat
257  
258end if
259###ダイアログ
260set strIconPath to "/System/Library/CoreServices/ManagedClient.app/Contents/PlugIns/ConfigurationProfilesUI.bundle/Contents/Resources/SystemPrefApp.icns"
261set aliasIconPath to POSIX file strIconPath as alias
262set recordResult to (display dialog "スクリプト戻り値です" with title "【3】スクリプト" default answer strScript buttons {"クリップボードにコピー", "キャンセル", "スクリプトエディタで開く"} default button "スクリプトエディタで開く" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
263#################################
264###【13】クリップボードにコピー
265if button returned of recordResult is "クリップボードにコピー" then
266  set strText to text returned of recordResult as text
267  ####ペーストボード宣言
268  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
269  set ocidText to (refMe's NSString's stringWithString:(strText))
270  appPasteboard's clearContents()
271  appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
272end if
273#################################
274###【14】OK押したらスクリプト生成
275if button returned of recordResult is "スクリプトエディタで開く" then
276  ##ファイル名
277  set strFileName to (strResponse & "." & (ocidPaneID as text) & "." & strPaneAnchor & ".applescript") as text
278  ##保存先はスクリプトメニュー
279  set appFileManager to refMe's NSFileManager's defaultManager()
280  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
281  set ocidLibraryDIrURL to ocidURLsArray's firstObject()
282  set ocidScriptDirPathURL to ocidLibraryDIrURL's URLByAppendingPathComponent:("Scripts/Applications/System Settings/Open")
283  ###フォルダを作って
284  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
285  ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
286  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidScriptDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
287  #非互換文字の置換
288  set strSaveFileName to doFileName4Mac(strFileName)
289  set ocidSaveFilePathURL to ocidScriptDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
290  ###スクリプトをテキストで保存
291  set ocidScript to refMe's NSString's stringWithString:(strScript)
292  ##改行はLFで
293  set ocidLFScript to ocidScript's stringByReplacingOccurrencesOfString:("\r") withString:("\n")
294  # set ocidEnc to (refMe's NSUTF16LittleEndianStringEncoding)
295  # ターミナルからの実行を配慮してUTF8に
296  set ocidEnc to (refMe's NSUTF8StringEncoding)
297  set listDone to ocidLFScript's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(ocidEnc) |error| :(reference)
298  delay 0.5
299  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
300  ###ターミナルから実行できるように755に
301  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
302  ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
303  set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidSaveFilePathURL's |path|()) |error| :(reference)
304  
305  
306  ###保存したスクリプトを開く
307  tell application "Script Editor"
308    open aliasSaveFilePath
309  end tell
310end if
311
312
313
314
315#######################################
316###ファイル名に使えない文字を全角に置換(Win互換)
317#######################################
318to doFileName4Mac(atgFileName)
319  ###受け取った値をテキストに
320  set strFileName to atgFileName as text
321  set ocidRetuenFileName to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
322  ocidRetuenFileName's setString:(strFileName)
323  ###置換レコード
324  set ocidLength to ocidRetuenFileName's |length|()
325  set ocidRange to refMe's NSMakeRange(0, ocidLength)
326  set ocidOption to (refMe's NSCaseInsensitiveSearch)
327  ###基本レコード
328  set recordProhibit to {|:|:":", |/|:"\\:", |\\|:"\\\\", |*|:"\\*", |(|:"\\(", |)|:"\\)", |[|:"\\[", |]|:"\\]", |{|:"\\{", |}|:"\\}", |'|:"\\'", |"|:"\\\"", |\||:"\\\\|", |;|:"\\;"} as record
329  set ocidProhibitDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
330  ocidProhibitDict's setDictionary:(recordProhibit)
331  ###キーのリストを取出して
332  set ocidKeyArray to ocidProhibitDict's allKeys()
333  ###キーの数だけ繰り返し
334  repeat with itemKey in ocidKeyArray
335    ##キーから
336    set strKey to itemKey as text
337    ##値を取出して
338    set strValue to (ocidProhibitDict's valueForKey:(itemKey)) as text
339    ##キー文字をヴァリュー文字に置換
340    (ocidRetuenFileName's replaceOccurrencesOfString:(strKey) withString:(strValue) options:(ocidOption) range:(ocidRange))
341  end repeat
342  ##置換されたテキストを
343  set strRetuenFileName to ocidRetuenFileName as text
344  ###戻す
345  return strRetuenFileName
346end doFileName4Mac
AppleScriptで生成しました

|

[システム設定] reveal anchorで開くと位置がずれる(macOS14.5)

ターゲットは『視差効果を減らす』
202405281252581430x940
サンプルコード

サンプルソース(参考)
行番号ソース
001tell application id "com.apple.systempreferences"
002  reveal anchor "AX_REDUCE_MOTION" of pane id "com.apple.Accessibility-Settings.extension"
003end tell
AppleScriptで生成しました

202405281253511430x940
サンプルコード

サンプルソース(参考)
行番号ソース
001tell application id "com.apple.finder"
002  open location "x-apple.systempreferences:com.apple.Accessibility-Settings.extension?AX_REDUCE_MOTION"
003end tell
AppleScriptで生成しました

|

システム設定オープン用のスクリプト作成補助 v5 (アンカーのないパネルに対応した)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#システム設定オープン用のスクリプト作成補助 v5
# アンカーのないタイプのパネルに対応した
# 作成されるスクリプトにウィンドウの最小化を解除する手順を入れた
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

set strBundleID to "com.apple.systempreferences" as text

############################
###【1】システム設定の起動を確定させる
set ocidRunAppArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
if (count of ocidRunAppArray) ≠ 0 then
log "起動中です"
  tell application id strBundleID to activate
else
  ####ゾンビ対策終了させてから処理させる
  tell application id strBundleID
    set numCntWindow to (count of every window) as integer
  end tell
  if numCntWindow = 0 then
    tell application id strBundleID to quit
  else
    tell application id strBundleID
close (every window)
quit
    end tell
  end if
  ####半ゾンビ化対策
  set ocidRunningApplication to refMe's NSRunningApplication
  set ocidAppArray to ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
  repeat with itemAppArray in ocidAppArray
itemAppArray's terminate
  end repeat
  ###システム設定を起動させる
  try
    tell application id strBundleID to activate
  on error
    tell application "System Settings" to activate
  end try
  ###起動待ち
  tell application id strBundleID
    ###起動確認 最大10秒
    repeat 10 times
activate
      set boolFrontMost to frontmost as boolean
log boolFrontMost
      if boolFrontMost is true then
        ###魔法の1秒
delay 0.5
        exit repeat
      else
delay 0.5
      end if
    end repeat
  end tell
end if
delay 3
############################
###【2】全てのパネルのIDを取得
tell application id "com.apple.systempreferences"
  set listPanelID to (id of every pane) as list
end tell

############################
###【A】正順レコード
set ocidPaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###【B】逆順レコード
set ocidReversePaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###【3】1で取得したリストの数だけ繰り返し
repeat with itemPanelID in listPanelID
  set strPanelID to itemPanelID as text
  tell application "System Settings"
    set strPanelName to (name of pane id strPanelID) as text
  end tell
  ###【A】正順レコード
  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelName) forKey:(strPanelID))
(ocidPaneDict's addEntriesFromDictionary:(ocidItemDict))
  ###【B】逆順レコード
  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelID) forKey:(strPanelName))
(ocidReversePaneDict's addEntriesFromDictionary:(ocidItemDict))
end repeat

############################
###【4】ダイアログ用に正順レコードのLISTを作る
set ocidAllValueArray to ocidPaneDict's allValues()
##ソートしておく
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(true) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidDescriptorArray's addObject:(ocidDescriptor)
set ocidSortedKey to (ocidAllValueArray's sortedArrayUsingDescriptors:(ocidDescriptorArray))
set listAllValueArray to ocidSortedKey as list
############################
###【5】ダイアログ  パネル
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
try
  set listResponse to (choose from list listAllValueArray with title "選んでください" with prompt "選択したパネルを開きます" default items (item 1 of listAllValueArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
else
  set strResponse to (item 1 of listResponse) as text
end if
log strResponse
############################
###【6】戻り値を逆順リストで検索してパネルIDを取得
set ocidPaneID to ocidReversePaneDict's valueForKey:(strResponse)
set strPaneID to ocidPaneID as text
log strPaneID

############################
###【7】アンカーの値の取得
tell application "System Settings"
  set listPaneAnchor to (name of anchors of pane strResponse) as list
log listPaneAnchor
end tell
###【7−1】一般選択時のみアンカーが無い
if strResponse is "一般" then
  set listPaneAnchor to {"Main"} as list
else if listPaneAnchor is {} then
  set listPaneAnchor to {""} as list
  #
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSLocalDomainMask))
  set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
  set ocidChkDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("PreferencePanes") isDirectory:(true)
  #
  set ocidOption to (refMe's NSDirectoryEnumerationSkipsSubdirectoryDescendants)
  set ocidPropertieArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidPropertieArray's addObject:(refMe's NSURLPathKey)
ocidPropertieArray's addObject:(refMe's NSURLNameKey)
  set listResponse to appFileManager's contentsOfDirectoryAtURL:(ocidChkDirPathURL) includingPropertiesForKeys:{} options:(ocidOption) |error|:(reference)
  set ocidFilePathURLArray to (item 1 of listResponse)
  repeat with itemFilePathURL in ocidFilePathURLArray
    set ocidPlistFilePathURL to (itemFilePathURL's URLByAppendingPathComponent:("Contents/Info.plist"))
    set listResponse to (refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error|:(reference))
    set ocidPlistData to (item 1 of listResponse)
    set strGetBundleID to (ocidPlistData's valueForKey:("CFBundleIdentifier")) as text
    if strGetBundleID is strPaneID then
      set ocidPaneURL to itemFilePathURL
      set strFilePath to (itemFilePathURL's |path|()) as text
    end if
  end repeat
end if

############################
###【8】ダイアログ アンカー
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
try
  set listResponse to (choose from list listPaneAnchor with title "選んでください" with prompt "選択したアンカーを開きます" default items (item 1 of listPaneAnchor) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
else
  set strPaneAnchor to (item 1 of listResponse) as text
end if
log strPaneAnchor


############################
###【9】URLにする
set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
###スキーム
ocidURLComponents's setScheme:("x-apple.systempreferences")
###パネルIDをパスにセット
ocidURLComponents's setPath:(ocidPaneID)
###アンカーをクエリーとして追加
ocidURLComponents's setQuery:(strPaneAnchor)
set ocidOpenAppURL to ocidURLComponents's |URL|
set strOpenAppURL to ocidOpenAppURL's absoluteString() as text
log strOpenAppURL

############################
###【10】ワークスペースで開く
###ファイルURLとパネルのURLをArrayにしておく
set ocidOpenUrlArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
ocidOpenUrlArray's insertObject:(ocidOpenAppURL) atIndex:0
###FinderでURLを開くのでFinderのURLを用意
set strBundleID to "com.apple.finder" as text
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidAppPathURL to appShardWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID)
###NSWorkspaceで開く
set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration()
ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true)
ocidOpenConfig's setAllowsRunningApplicationSubstitution:(refMe's NSNumber's numberWithBool:true)
appShardWorkspace's openURLs:(ocidOpenUrlArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)

####システム設定が前面に来るまで待つ
repeat 20 times
  set boolFrontMost to frontmost of application id "com.apple.systempreferences"
  if boolFrontMost is false then
    tell application id "com.apple.systempreferences" to activate
  else
    exit repeat
  end if
delay 0.2
end repeat


#################################
###【11】ダイアログ用に値を用意
if listPaneAnchor is {""} then
  set strScript to ("#!/usr/bin/env osascript\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\n#\n# com.cocolog-nifty.quicktimer.icefloe\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\nuse AppleScript version \"2.8\"\nuse framework \"Foundation\"\nuse framework \"AppKit\"\nuse scripting additions\n\nproperty refMe : a reference to current application\n\nset strFilePath to (\"" & strFilePath & "\") as text\nset ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)\nset ocidFilePath to ocidFilePathStr's stringByStandardizingPath()\nset ocidSystemPreferencesURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)\n##\nset ocidWorkspace to refMe's NSWorkspace's sharedWorkspace()\nset boolDone to ocidWorkspace's openURL:(ocidSystemPreferencesURL)\nif boolDone is false then\n\tset aliasFilePath to (POSIX file strFilePath) as alias\n\ttell application \"Finder\"\n\t\topen location aliasFilePath\n\tend tell\nend if\nreturn") as text
else
  set strScript to ("#!/usr/bin/env osascript\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\n#com.cocolog-nifty.quicktimer.icefloe\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\nuse AppleScript version \"2.8\"\nuse framework \"Foundation\"\nuse framework \"AppKit\"\nuse framework \"UniformTypeIdentifiers\"\nuse scripting additions\nproperty refMe : a reference to current application\nset strBundleID to \"com.apple.systempreferences\" as text\n###URLにする\nset ocidURLComponents to refMe's NSURLComponents's alloc()'s init()\n###スキーム\nocidURLComponents's setScheme:(\"x-apple.systempreferences\")\n###パネルIDをパスにセット\nocidURLComponents's setPath:(\"" & strPaneID & "\")\n###アンカーをクエリーとして追加\nocidURLComponents's setQuery:(\"" & strPaneAnchor & "\")\nset ocidOpenAppURL to ocidURLComponents's |URL|\nset strOpenAppURL to ocidOpenAppURL's absoluteString() as text\n###ワークスペースで開く\nset appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()\nset boolDone to appShardWorkspace's openURL:(ocidOpenAppURL)\nlog boolDone\nif boolDone is false then\ntell application id \"com.apple.systempreferences\"\nactivate\nset miniaturized of the settings window to false\nend tell\ntell application id \"com.apple.systempreferences\"\nreveal anchor \"" & strPaneAnchor & "\" of pane id \"" & strPaneID & "\"\nend tell\ntell application id \"com.apple.finder\"\nopen location \"" & strOpenAppURL & "\"\nend tell\ntell application id \"com.apple.systempreferences\" to activate\nend if\nreturn\n") as text
end if
#################################
###【12】戻り値ダイアログ
set strName to (name of current application) as text
log strName
if strName is "osascript" then
  repeat 20 times
    set boolFrontMost to frontmost of application "Finder"
    if boolFrontMost is false then
      tell application "Finder" to activate
    else
      exit repeat
    end if
delay 0.2
  end repeat
else
  repeat 5 times
    set boolFrontMost to frontmost of application "Script Editor"
log boolFrontMost
    if boolFrontMost is false then
      tell current application to activate
    else
      exit repeat
    end if
delay 0.2
  end repeat
  
end if
###ダイアログ
set strIconPath to "/System/Library/CoreServices/ManagedClient.app/Contents/PlugIns/ConfigurationProfilesUI.bundle/Contents/Resources/SystemPrefApp.icns"
set aliasIconPath to POSIX file strIconPath as alias
set recordResult to (display dialog "スクリプト戻り値です" with title "【3】スクリプト" default answer strScript buttons {"クリップボードにコピー", "キャンセル", "スクリプトエディタで開く"} default button "スクリプトエディタで開く" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
#################################
###【13】クリップボードにコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if
#################################
###【14】OK押したらスクリプト生成
if button returned of recordResult is "スクリプトエディタで開く" then
  ##ファイル名
  set strFileName to (strResponse & "." & (ocidPaneID as text) & "." & strPaneAnchor & ".applescript") as text
  ##保存先はスクリプトメニュー
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidLibraryDIrURL to ocidURLsArray's firstObject()
  set ocidScriptDirPathURL to ocidLibraryDIrURL's URLByAppendingPathComponent:("Scripts/Applications/System Settings/Open")
  ###フォルダを作って
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidScriptDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  #非互換文字の置換
  set strSaveFileName to doFileName4Mac(strFileName)
  set ocidSaveFilePathURL to ocidScriptDirPathURL's URLByAppendingPathComponent:(strSaveFileName)
  ###スクリプトをテキストで保存
  set ocidScript to refMe's NSString's stringWithString:(strScript)
  ##改行はLFで
  set ocidLFScript to ocidScript's stringByReplacingOccurrencesOfString:("\r") withString:("\n")
  # set ocidEnc to (refMe's NSUTF16LittleEndianStringEncoding)
  # ターミナルからの実行を配慮してUTF8に
  set ocidEnc to (refMe's NSUTF8StringEncoding)
  set listDone to ocidLFScript's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(ocidEnc) |error|:(reference)
delay 0.5
  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
  ###ターミナルから実行できるように755に
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidSaveFilePathURL's |path|()) |error|:(reference)
  
  
  ###保存したスクリプトを開く
  tell application "Script Editor"
open aliasSaveFilePath
  end tell
end if




#######################################
###ファイル名に使えない文字を全角に置換(Win互換)
#######################################
to doFileName4Mac(atgFileName)
  ###受け取った値をテキストに
  set strFileName to atgFileName as text
  set ocidRetuenFileName to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidRetuenFileName's setString:(strFileName)
  ###置換レコード
  set ocidLength to ocidRetuenFileName's |length|()
  set ocidRange to refMe's NSMakeRange(0, ocidLength)
  set ocidOption to (refMe's NSCaseInsensitiveSearch)
  ###基本レコード
  set recordProhibit to {|:|:":", |/|:"\\:", |\\|:"\\\\", |*|:"\\*", |(|:"\\(", |)|:"\\)", |[|:"\\[", |]|:"\\]", |{|:"\\{", |}|:"\\}", |'|:"\\'", |"|:"\\\"", |\||:"\\\\|", |;|:"\\;"} as record
set ocidProhibitDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidProhibitDict's setDictionary:(recordProhibit)
###キーのリストを取出して
set ocidKeyArray to ocidProhibitDict's allKeys()
###キーの数だけ繰り返し
repeat with itemKey in ocidKeyArray
##キーから
set strKey to itemKey as text
##値を取出して
set strValue to (ocidProhibitDict's valueForKey:(itemKey)) as text
##キー文字をヴァリュー文字に置換
(ocidRetuenFileName's replaceOccurrencesOfString:(strKey) withString:(strValue) options:(ocidOption) range:(ocidRange))
end repeat
##置換されたテキストを
set strRetuenFileName to ocidRetuenFileName as text
###戻す
return strRetuenFileName
end doFileName4Mac

|

システム設定をオープンさせるスクリプトの作成補助v4


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#システム設定オープン用のスクリプト作成補助 v4
# 作成されるスクリプトにウィンドウの最小化を解除する手順を入れた
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

set strBundleID to "com.apple.systempreferences" as text


############################
###【1】システム設定の起動を確定させる
set ocidRunAppArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
if (count of ocidRunAppArray) ≠ 0 then
log "起動中です"
  tell application id strBundleID to activate
else
  ####ゾンビ対策終了させてから処理させる
  tell application id strBundleID
    set numCntWindow to (count of every window) as integer
  end tell
  if numCntWindow = 0 then
    tell application id strBundleID to quit
  else
    tell application id strBundleID
close (every window)
quit
    end tell
  end if
  ####半ゾンビ化対策
  set ocidRunningApplication to refMe's NSRunningApplication
  set ocidAppArray to ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
  repeat with itemAppArray in ocidAppArray
itemAppArray's terminate
  end repeat
  ###システム設定を起動させる
  try
    tell application id strBundleID to activate
  on error
    tell application "System Settings" to activate
  end try
  ###起動待ち
  tell application id strBundleID
    ###起動確認 最大10秒
    repeat 10 times
activate
      set boolFrontMost to frontmost as boolean
log boolFrontMost
      if boolFrontMost is true then
        ###魔法の1秒
delay 0.5
        exit repeat
      else
delay 0.5
      end if
    end repeat
  end tell
end if
############################
###【2】全てのパネルのIDを取得
tell application id "com.apple.systempreferences"
  set listPanelID to (id of every pane) as list
end tell

############################
###【A】正順レコード
set ocidPaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###【B】逆順レコード
set ocidReversePaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###【3】1で取得したリストの数だけ繰り返し
repeat with itemPanelID in listPanelID
  set strPanelID to itemPanelID as text
  tell application "System Settings"
    set strPanelName to (name of pane id strPanelID) as text
  end tell
  ###【A】正順レコード
  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelName) forKey:(strPanelID))
(ocidPaneDict's addEntriesFromDictionary:(ocidItemDict))
  ###【B】逆順レコード
  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelID) forKey:(strPanelName))
(ocidReversePaneDict's addEntriesFromDictionary:(ocidItemDict))
end repeat

############################
###【4】ダイアログ用に正順レコードのLISTを作る
set ocidAllValueArray to ocidPaneDict's allValues()
##ソートしておく
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(true) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidDescriptorArray's addObject:(ocidDescriptor)
set ocidSortedKey to (ocidAllValueArray's sortedArrayUsingDescriptors:(ocidDescriptorArray))
set listAllValueArray to ocidSortedKey as list
############################
###【5】ダイアログ  パネル
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
try
  set listResponse to (choose from list listAllValueArray with title "選んでください" with prompt "選択したパネルを開きます" default items (item 1 of listAllValueArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
else
  set strResponse to (item 1 of listResponse) as text
end if
log strResponse
############################
###【6】戻り値を逆順リストで検索してパネルIDを取得
set ocidPaneID to ocidReversePaneDict's valueForKey:(strResponse)
set strPaneID to ocidPaneID as text
log "strPaneID" & strPaneID
############################
###【7】アンカーの値の取得
tell application "System Settings"
  set listPaneAnchor to (name of anchors of pane strResponse) as list
log listPaneAnchor
end tell
###【7−1】一般選択時のみアンカーが無い
if strResponse is "一般" then
  set listPaneAnchor to {"Main"} as list
end if
############################
###【8】ダイアログ アンカー
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
try
  set listResponse to (choose from list listPaneAnchor with title "選んでください" with prompt "選択したアンカーを開きます" default items (item 1 of listPaneAnchor) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
else
  set strPaneAnchor to (item 1 of listResponse) as text
end if
log strPaneAnchor


############################
###【9】URLにする
set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
###スキーム
ocidURLComponents's setScheme:("x-apple.systempreferences")
###パネルIDをパスにセット
ocidURLComponents's setPath:(ocidPaneID)
###アンカーをクエリーとして追加
ocidURLComponents's setQuery:(strPaneAnchor)
set ocidOpenAppURL to ocidURLComponents's |URL|
set strOpenAppURL to ocidOpenAppURL's absoluteString() as text
log strOpenAppURL

############################
###【10】ワークスペースで開く
###ファイルURLとパネルのURLをArrayにしておく
set ocidOpenUrlArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
ocidOpenUrlArray's insertObject:(ocidOpenAppURL) atIndex:0
###FinderでURLを開くのでFinderのURLを用意
set strBundleID to "com.apple.finder" as text
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidAppPathURL to appShardWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID)
###NSWorkspaceで開く
set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration()
ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true)
ocidOpenConfig's setAllowsRunningApplicationSubstitution:(refMe's NSNumber's numberWithBool:true)
appShardWorkspace's openURLs:(ocidOpenUrlArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)

####システム設定が前面に来るまで待つ
repeat 20 times
  set boolFrontMost to frontmost of application id "com.apple.systempreferences"
  if boolFrontMost is false then
    tell application id "com.apple.systempreferences" to activate
  else
    exit repeat
  end if
delay 0.2
end repeat


#################################
###【11】ダイアログ用に値を用意
set strScript to ("#!/usr/bin/env osascript\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\n#com.cocolog-nifty.quicktimer.icefloe\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\nuse AppleScript version \"2.8\"\nuse framework \"Foundation\"\nuse framework \"AppKit\"\nuse framework \"UniformTypeIdentifiers\"\nuse scripting additions\nproperty refMe : a reference to current application\nset strBundleID to \"com.apple.systempreferences\" as text\n###URLにする\nset ocidURLComponents to refMe's NSURLComponents's alloc()'s init()\n###スキーム\nocidURLComponents's setScheme:(\"x-apple.systempreferences\")\n###パネルIDをパスにセット\nocidURLComponents's setPath:(\"" & strPaneID & "\")\n###アンカーをクエリーとして追加\nocidURLComponents's setQuery:(\"" & strPaneAnchor & "\")\nset ocidOpenAppURL to ocidURLComponents's |URL|\nset strOpenAppURL to ocidOpenAppURL's absoluteString() as text\n###ワークスペースで開く\nset appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()\nset boolDone to appShardWorkspace's openURL:(ocidOpenAppURL)\nlog boolDone\nif boolDone is false then\ntell application id \"com.apple.systempreferences\"\nactivate\nset miniaturized of the settings window to false\nend tell\ntell application id \"com.apple.systempreferences\"\nreveal anchor \"" & strPaneAnchor & "\" of pane id \"" & strPaneID & "\"\nend tell\ntell application id \"com.apple.finder\"\nopen location \"" & strOpenAppURL & "\"\nend tell\ntell application id \"com.apple.systempreferences\" to activate\nend if\nreturn\n")

#################################
###【12】戻り値ダイアログ
set strName to (name of current application) as text
log strName
if strName is "osascript" then
  repeat 20 times
    set boolFrontMost to frontmost of application "Finder"
    if boolFrontMost is false then
      tell application "Finder" to activate
    else
      exit repeat
    end if
delay 0.2
  end repeat
else
  repeat 5 times
    set boolFrontMost to frontmost of application "Script Editor"
log boolFrontMost
    if boolFrontMost is false then
      tell current application to activate
    else
      exit repeat
    end if
delay 0.2
  end repeat
  
end if
###ダイアログ
set strIconPath to "/System/Library/CoreServices/ManagedClient.app/Contents/PlugIns/ConfigurationProfilesUI.bundle/Contents/Resources/SystemPrefApp.icns"
set aliasIconPath to POSIX file strIconPath as alias
set recordResult to (display dialog "スクリプト戻り値です" with title "【3】スクリプト" default answer strScript buttons {"クリップボードにコピー", "キャンセル", "スクリプトエディタで開く"} default button "スクリプトエディタで開く" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
#################################
###【13】クリップボードにコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if
#################################
###【14】OK押したらスクリプト生成
if button returned of recordResult is "スクリプトエディタで開く" then
  ##ファイル名
  set strFileName to (strResponse & "." & (ocidPaneID as text) & "." & strPaneAnchor & ".applescript") as text
  ##保存先はスクリプトメニュー
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidLibraryDIrURL to ocidURLsArray's firstObject()
  set ocidScriptDirPathURL to ocidLibraryDIrURL's URLByAppendingPathComponent:("Scripts/Applications/System Settings/Open")
  ###フォルダを作って
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidScriptDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set ocidSaveFilePathURL to ocidScriptDirPathURL's URLByAppendingPathComponent:(strFileName)
  ###スクリプトをテキストで保存
  set ocidScript to refMe's NSString's stringWithString:(strScript)
  ##改行はLFで
  set ocidLFScript to ocidScript's stringByReplacingOccurrencesOfString:("\r") withString:("\n")
  # set ocidEnc to (refMe's NSUTF16LittleEndianStringEncoding)
  # ターミナルからの実行を配慮してUTF8に
  set ocidEnc to (refMe's NSUTF8StringEncoding)
  set listDone to ocidLFScript's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(ocidEnc) |error|:(reference)
delay 0.5
  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
  ###ターミナルから実行できるように755に
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidSaveFilePathURL's |path|()) |error|:(reference)
  
  
  ###保存したスクリプトを開く
  tell application "Script Editor"
open aliasSaveFilePath
  end tell
end if



|

[com.apple.systempreferences]システム設定はlaunch→NG activate→OK

macOS14 現時点でのシステム設定の起動方法


tell application id "com.apple.systempreferences" to launch
-->launchするとストールする

tell application id "com.apple.systempreferences" to activate
-->launchしないでactivateで起動させるのが現時点で解決策

|

システム設定パネルID追加

PLIST2HTML:prefsmapping.plist.html macOS14追加
連番キーの名前キーの値
1com.apple.preferences.walletcom.apple.WalletSettingsExtension
2com.apple.preference.universalaccess&anchorId=Accessibility_Shortcutcom.apple.Accessibility-Settings.extension?Accessibility_Shortcut
3com.apple.preference.universalaccess&anchorId=Siricom.apple.Accessibility-Settings.extension?Siri
4com.apple.preference.universalaccess&anchorId=TextToSpeechcom.apple.Accessibility-Settings.extension?TextToSpeech
5com.apple.preference.universalaccess&anchorId=Seeing_Zoomcom.apple.Accessibility-Settings.extension?Seeing_Zoom
6com.apple.preference.trackpadcom.apple.Trackpad-Settings.extension
7com.apple.preference.universalaccess&anchorId=Seeing_VoiceOvercom.apple.Accessibility-Settings.extension?Seeing_VoiceOver
8com.apple.preference.securitycom.apple.settings.PrivacySecurity.extension
9com.apple.preference.screentimecom.apple.Screen-Time-Settings.extension
10com.apple.preferences.FamilySharingPrefPanecom.apple.Family-Settings.extension*Family
11com.apple.preference.universalaccess&anchorId=Media_Descriptionscom.apple.Accessibility-Settings.extension?Media_Descriptions
12com.apple.preference.universalaccesscom.apple.Accessibility-Settings.extension
13com.apple.preference.screentime&anchorId=Downtimecom.apple.Screen-Time-Settings.extension?path=downtime
14com.apple.preferences.Bluetoothcom.apple.BluetoothSettings
15com.apple.preferences.softwareupdatecom.apple.Software-Update-Settings.extension
16com.apple.preference.desktopscreeneffectcom.apple.Wallpaper-Settings.extension
17com.apple.prefs.backupcom.apple.Time-Machine-Settings.extension
18com.apple.preference.batterycom.apple.Battery-Settings.extension*BatteryPreferences
19com.apple.preference.networkcom.apple.Network-Settings.extension
20com.apple.preference.screentime&anchorId=AlwaysAllowedcom.apple.Screen-Time-Settings.extension?path=always-allowed
21com.apple.preferences.configurationprofilescom.apple.Profiles-Settings.extension
22com.apple.preference.screentime&anchorId=DailyUsagecom.apple.Screen-Time-Settings.extension?path=app-usage
23com.apple.preference.universalaccess&anchorId=Mousecom.apple.Accessibility-Settings.extension?Mouse
24com.apple.preferences.AppleIDPrefPanecom.apple.systempreferences.AppleIDSettings*AppleIDSettings
25com.apple.preferences.extensionscom.apple.ExtensionsPreferences
26com.apple.preference.notificationscom.apple.Notifications-Settings.extension
27com.apple.preference.keyboardcom.apple.Keyboard-Settings.extension
28com.apple.preference.dockcom.apple.Desktop-Settings.extension
29com.apple.preference.digihub.discscom.apple.CD-DVD-Settings.extension
30com.apple.preference.screentime&anchorId=ViewUsageLimitcom.apple.Screen-Time-Settings.extension?path=app-limits
31com.apple.preference.spotlightcom.apple.Siri-Settings.extension
32com.apple.preference.screentime&anchorId=ContentAndPrivacycom.apple.Screen-Time-Settings.extension?path=content-and-privacy
33com.apple.preference.universalaccess&anchorId=Switchcom.apple.Accessibility-Settings.extension?Switch
34com.apple.preferences.passwordcom.apple.Touch-ID-Settings.extension*TouchIDPasswordPrefs
35com.apple.Localizationcom.apple.Localization-Settings.extension
36com.apple.preference.universalaccess&anchorId=Seeing_Displaycom.apple.Accessibility-Settings.extension?Seeing_Display
37com.apple.preference.startupdiskcom.apple.Startup-Disk-Settings.extension
38com.apple.preference.speechcom.apple.Siri-Settings.extension
39com.apple.preference.datetimecom.apple.Date-Time-Settings.extension
40com.apple.preference.displayscom.apple.Displays-Settings.extension
41com.apple.preference.universalaccess&anchorId=Hearingcom.apple.Accessibility-Settings.extension?Hearing
42com.apple.preference.screentime&anchorId=DailyPickupscom.apple.Screen-Time-Settings.extension?path=pickups
43com.apple.preferences.ClassKitPreferencePanecom.apple.ClassKit-Settings.extension
44com.apple.preference.mousecom.apple.Mouse-Settings.extension
45com.apple.preferences.EnergySaverPrefPanecom.apple.Battery-Settings.extension
46com.apple.preferences.internetaccountscom.apple.Internet-Accounts-Settings.extension
47com.apple.preferences.sharingcom.apple.Sharing-Settings.extension
48com.apple.preference.universalaccess&anchorId=Captioningcom.apple.Accessibility-Settings.extension?Captioning
49com.apple.preference.screentime&anchorId=CommunicationLimitcom.apple.Screen-Time-Settings.extension?path=communication-limits
50com.apple.preference.universalaccess&anchorId=Dictationcom.apple.Accessibility-Settings.extension?Dictation
51com.apple.preference.printfaxcom.apple.Print-Scan-Settings.extension
52com.apple.preference.generalcom.apple.Appearance-Settings.extension
53com.apple.preference.screentime&anchorId=DailyNotificationscom.apple.Screen-Time-Settings.extension?path=notifications
54com.apple.preference.soundcom.apple.Sound-Settings.extension
55com.apple.preferences.userscom.apple.Users-Groups-Settings.extension
56com.apple.preference.universalaccess&anchorId=Keyboardcom.apple.Accessibility-Settings.extension?Keyboard
57com.apple.Passwordscom.apple.Passwords-Settings.extension
合計57項目
com.apple.helpviewer Plist情報:prefsmapping.plist.html
項番キーの名前キーの値
1com.apple.preferences.walletcom.apple.WalletSettingsExtension
2com.apple.preference.universalaccess&anchorId=Accessibility_Shortcutcom.apple.Accessibility-Settings.extension?Accessibility_Shortcut
3com.apple.preference.universalaccess&anchorId=Siricom.apple.Accessibility-Settings.extension?Siri
4com.apple.preference.universalaccess&anchorId=TextToSpeechcom.apple.Accessibility-Settings.extension?TextToSpeech
5com.apple.preference.universalaccess&anchorId=Seeing_Zoomcom.apple.Accessibility-Settings.extension?Seeing_Zoom
6com.apple.preference.trackpadcom.apple.Trackpad-Settings.extension
7com.apple.preference.universalaccess&anchorId=Seeing_VoiceOvercom.apple.Accessibility-Settings.extension?Seeing_VoiceOver
8com.apple.preference.securitycom.apple.settings.PrivacySecurity.extension
9com.apple.preference.screentimecom.apple.Screen-Time-Settings.extension
10com.apple.preferences.FamilySharingPrefPanecom.apple.Family-Settings.extension*Family
11com.apple.preference.universalaccess&anchorId=Media_Descriptionscom.apple.Accessibility-Settings.extension?Media_Descriptions
12com.apple.preference.universalaccesscom.apple.Accessibility-Settings.extension
13com.apple.preference.screentime&anchorId=Downtimecom.apple.Screen-Time-Settings.extension?path=downtime
14com.apple.preferences.Bluetoothcom.apple.BluetoothSettings
15com.apple.preferences.softwareupdatecom.apple.Software-Update-Settings.extension
16com.apple.preference.desktopscreeneffectcom.apple.Wallpaper-Settings.extension
17com.apple.prefs.backupcom.apple.Time-Machine-Settings.extension
18com.apple.preference.batterycom.apple.Battery-Settings.extension*BatteryPreferences
19com.apple.preference.networkcom.apple.Network-Settings.extension
20com.apple.preference.screentime&anchorId=AlwaysAllowedcom.apple.Screen-Time-Settings.extension?path=always-allowed
21com.apple.preferences.configurationprofilescom.apple.Profiles-Settings.extension
22com.apple.preference.screentime&anchorId=DailyUsagecom.apple.Screen-Time-Settings.extension?path=app-usage
23com.apple.preference.universalaccess&anchorId=Mousecom.apple.Accessibility-Settings.extension?Mouse
24com.apple.preferences.AppleIDPrefPanecom.apple.systempreferences.AppleIDSettings*AppleIDSettings
25com.apple.preferences.extensionscom.apple.ExtensionsPreferences
26com.apple.preference.notificationscom.apple.Notifications-Settings.extension
27com.apple.preference.keyboardcom.apple.Keyboard-Settings.extension
28com.apple.preference.dockcom.apple.Desktop-Settings.extension
29com.apple.preference.screentime&anchorId=ViewUsageLimitcom.apple.Screen-Time-Settings.extension?path=app-limits
30com.apple.preference.screentime&anchorId=ContentAndPrivacycom.apple.Screen-Time-Settings.extension?path=content-and-privacy
31com.apple.preference.spotlightcom.apple.Siri-Settings.extension
32com.apple.preference.digihub.discscom.apple.CD-DVD-Settings.extension
33com.apple.preference.universalaccess&anchorId=Switchcom.apple.Accessibility-Settings.extension?Switch
34com.apple.preferences.passwordcom.apple.Touch-ID-Settings.extension*TouchIDPasswordPrefs
35com.apple.Localizationcom.apple.Localization-Settings.extension
36com.apple.preference.universalaccess&anchorId=Seeing_Displaycom.apple.Accessibility-Settings.extension?Seeing_Display
37com.apple.preference.startupdiskcom.apple.Startup-Disk-Settings.extension
38com.apple.preference.speechcom.apple.Siri-Settings.extension
39com.apple.preference.datetimecom.apple.Date-Time-Settings.extension
40com.apple.preference.displayscom.apple.Displays-Settings.extension
41com.apple.preference.universalaccess&anchorId=Hearingcom.apple.Accessibility-Settings.extension?Hearing
42com.apple.preference.screentime&anchorId=DailyPickupscom.apple.Screen-Time-Settings.extension?path=pickups
43com.apple.preferences.ClassKitPreferencePanecom.apple.ClassKit-Settings.extension
44com.apple.preference.mousecom.apple.Mouse-Settings.extension
45com.apple.preferences.EnergySaverPrefPanecom.apple.Battery-Settings.extension
46com.apple.preferences.internetaccountscom.apple.Internet-Accounts-Settings.extension
47com.apple.preference.screentime&anchorId=CommunicationLimitcom.apple.Screen-Time-Settings.extension?path=communication-limits
48com.apple.preferences.sharingcom.apple.Sharing-Settings.extension
49com.apple.preference.universalaccess&anchorId=Captioningcom.apple.Accessibility-Settings.extension?Captioning
50com.apple.preference.universalaccess&anchorId=Dictationcom.apple.Accessibility-Settings.extension?Dictation
51com.apple.preference.printfaxcom.apple.Print-Scan-Settings.extension
52com.apple.preference.generalcom.apple.Appearance-Settings.extension
53com.apple.preference.screentime&anchorId=DailyNotificationscom.apple.Screen-Time-Settings.extension?path=notifications
54com.apple.preference.soundcom.apple.Sound-Settings.extension
55com.apple.preferences.userscom.apple.Users-Groups-Settings.extension
56com.apple.preference.universalaccess&anchorId=Keyboardcom.apple.Accessibility-Settings.extension?Keyboard
57com.apple.Passwordscom.apple.Passwords-Settings.extension
合計57項目

|

システム設定をオープンさせるスクリプトの作成補助v3


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#システム設定オープン用のスクリプト作成補助 v3
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

set strBundleID to "com.apple.systempreferences" as text


############################
###【1】システム設定の起動を確定させる
set ocidRunAppArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
if (count of ocidRunAppArray) ≠ 0 then
  log "起動中です"
  tell application id strBundleID to activate
else
  ####ゾンビ対策終了させてから処理させる
  tell application id strBundleID
    set numCntWindow to (count of every window) as integer
  end tell
  if numCntWindow = 0 then
    tell application id strBundleID to quit
  else
    tell application id strBundleID
      close (every window)
      quit
    end tell
  end if
  ####半ゾンビ化対策
  set ocidRunningApplication to refMe's NSRunningApplication
  set ocidAppArray to ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
  repeat with itemAppArray in ocidAppArray
itemAppArray's terminate
  end repeat
  ###システム設定を起動させる
  try
    tell application id strBundleID to activate
  on error
    tell application "System Settings" to activate
  end try
  ###起動待ち
  tell application id strBundleID
    ###起動確認 最大10秒
    repeat 10 times
      activate
      set boolFrontMost to frontmost as boolean
      log boolFrontMost
      if boolFrontMost is true then
###魔法の1秒
delay 0.5
exit repeat
      else
delay 0.5
      end if
    end repeat
  end tell
end if
############################
###【2】全てのパネルのIDを取得
tell application id "com.apple.systempreferences"
  set listPanelID to (id of every pane) as list
end tell

############################
###【A】正順レコード
set ocidPaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###【B】逆順レコード
set ocidReversePaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###【3】1で取得したリストの数だけ繰り返し
repeat with itemPanelID in listPanelID
  set strPanelID to itemPanelID as text
  tell application "System Settings"
    set strPanelName to (name of pane id strPanelID) as text
  end tell
  ###【A】正順レコード
  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelName) forKey:(strPanelID))
(ocidPaneDict's addEntriesFromDictionary:(ocidItemDict))
  ###【B】逆順レコード
  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelID) forKey:(strPanelName))
(ocidReversePaneDict's addEntriesFromDictionary:(ocidItemDict))
end repeat

############################
###【4】ダイアログ用に正順レコードのLISTを作る
set ocidAllValueArray to ocidPaneDict's allValues()
##ソートしておく
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(true) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidDescriptorArray's addObject:(ocidDescriptor)
set ocidSortedKey to (ocidAllValueArray's sortedArrayUsingDescriptors:(ocidDescriptorArray))
set listAllValueArray to ocidSortedKey as list
############################
###【5】ダイアログ  パネル
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
try
  set listResponse to (choose from list listAllValueArray with title "選んでください" with prompt "選択したパネルを開きます" default items (item 1 of listAllValueArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
else
  set strResponse to (item 1 of listResponse) as text
end if
log strResponse
############################
###【6】戻り値を逆順リストで検索してパネルIDを取得
set ocidPaneID to ocidReversePaneDict's valueForKey:(strResponse)
set strPaneID to ocidPaneID as text
log "strPaneID" & strPaneID
############################
###【7】アンカーの値の取得
tell application "System Settings"
  set listPaneAnchor to (name of anchors of pane strResponse) as list
  log listPaneAnchor
end tell
###【7−1】一般選択時のみアンカーが無い
if strResponse is "一般" then
  set listPaneAnchor to {"Main"} as list
end if
############################
###【8】ダイアログ アンカー
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
try
  set listResponse to (choose from list listPaneAnchor with title "選んでください" with prompt "選択したアンカーを開きます" default items (item 1 of listPaneAnchor) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
else
  set strPaneAnchor to (item 1 of listResponse) as text
end if
log strPaneAnchor


############################
###【9】URLにする
set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
###スキーム
ocidURLComponents's setScheme:("x-apple.systempreferences")
###パネルIDをパスにセット
ocidURLComponents's setPath:(ocidPaneID)
###アンカーをクエリーとして追加
ocidURLComponents's setQuery:(strPaneAnchor)
set ocidOpenAppURL to ocidURLComponents's |URL|
set strOpenAppURL to ocidOpenAppURL's absoluteString() as text
log strOpenAppURL

############################
###【10】ワークスペースで開く
###ファイルURLとパネルのURLをArrayにしておく
set ocidOpenUrlArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
ocidOpenUrlArray's insertObject:(ocidOpenAppURL) atIndex:0
###FinderでURLを開くのでFinderのURLを用意
set strBundleID to "com.apple.finder" as text
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidAppPathURL to appShardWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID)
###NSWorkspaceで開く
set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration()
ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true)
ocidOpenConfig's setAllowsRunningApplicationSubstitution:(refMe's NSNumber's numberWithBool:true)
appShardWorkspace's openURLs:(ocidOpenUrlArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)

####システム設定が前面に来るまで待つ
repeat 20 times
  set boolFrontMost to frontmost of application id "com.apple.systempreferences"
  if boolFrontMost is false then
    tell application id "com.apple.systempreferences" to activate
  else
    exit repeat
  end if
  delay 0.2
end repeat


#################################
###【11】ダイアログ用に値を用意
set strScript to ("#!/usr/bin/env osascript\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\n#com.cocolog-nifty.quicktimer.icefloe\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\nuse AppleScript version \"2.8\"\nuse framework \"Foundation\"\nuse framework \"AppKit\"\nuse framework \"UniformTypeIdentifiers\"\nuse scripting additions\nproperty refMe : a reference to current application\nset strBundleID to \"com.apple.systempreferences\" as text\n###URLにする\nset ocidURLComponents to refMe's NSURLComponents's alloc()'s init()\n###スキーム\nocidURLComponents's setScheme:(\"x-apple.systempreferences\")\n###パネルIDをパスにセット\nocidURLComponents's setPath:(\"" & strPaneID & "\")\n###アンカーをクエリーとして追加\nocidURLComponents's setQuery:(\"" & strPaneAnchor & "\")\nset ocidOpenAppURL to ocidURLComponents's |URL|\nset strOpenAppURL to ocidOpenAppURL's absoluteString() as text\n###ワークスペースで開く\nset appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()\nset boolDone to appShardWorkspace's openURL:(ocidOpenAppURL)\nlog boolDone\nif boolDone is false then\ntell application id \"com.apple.systempreferences\" to activate\ntell application id \"com.apple.systempreferences\"\nreveal anchor \"" & strPaneAnchor & "\" of pane id \"" & strPaneID & "\"\nend tell\ntell application id \"com.apple.finder\"\nopen location \"" & strOpenAppURL & "\"\nend tell\ntell application id \"com.apple.systempreferences\" to activate\nend if\nreturn\n")

#################################
###【12】戻り値ダイアログ
set strName to (name of current application) as text
log strName
if strName is "osascript" then
  repeat 20 times
    set boolFrontMost to frontmost of application "Finder"
    if boolFrontMost is false then
      tell application "Finder" to activate
    else
      exit repeat
    end if
    delay 0.2
  end repeat
else
  repeat 5 times
    set boolFrontMost to frontmost of application "Script Editor"
    log boolFrontMost
    if boolFrontMost is false then
      tell current application to activate
    else
      exit repeat
    end if
    delay 0.2
  end repeat
  
end if
###ダイアログ
set strIconPath to "/System/Library/CoreServices/ManagedClient.app/Contents/PlugIns/ConfigurationProfilesUI.bundle/Contents/Resources/SystemPrefApp.icns"
set aliasIconPath to POSIX file strIconPath as alias
set recordResult to (display dialog "スクリプト戻り値です" with title "【3】スクリプト" default answer strScript buttons {"クリップボードにコピー", "キャンセル", "スクリプトエディタで開く"} default button "スクリプトエディタで開く" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
#################################
###【13】クリップボードにコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if
#################################
###【14】OK押したらスクリプト生成
if button returned of recordResult is "スクリプトエディタで開く" then
  ##ファイル名
  set strFileName to (strResponse & "." & (ocidPaneID as text) & "." & strPaneAnchor & ".applescript") as text
  ##保存先はスクリプトメニュー
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidLibraryDIrURL to ocidURLsArray's firstObject()
  set ocidScriptDirPathURL to ocidLibraryDIrURL's URLByAppendingPathComponent:("Scripts/Applications/System Settings/Open")
  ###フォルダを作って
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidScriptDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set ocidSaveFilePathURL to ocidScriptDirPathURL's URLByAppendingPathComponent:(strFileName)
  ###スクリプトをテキストで保存
  set ocidScript to refMe's NSString's stringWithString:(strScript)
  ##改行はLFで
  set ocidLFScript to ocidScript's stringByReplacingOccurrencesOfString:("\r") withString:("\n")
  # set ocidEnc to (refMe's NSUTF16LittleEndianStringEncoding)
  # ターミナルからの実行を配慮してUTF8に
  set ocidEnc to (refMe's NSUTF8StringEncoding)
  set listDone to ocidLFScript's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(ocidEnc) |error|:(reference)
  delay 0.5
  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
  ###ターミナルから実行できるように755に
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidSaveFilePathURL's |path|()) |error|:(reference)
  
  
  ###保存したスクリプトを開く
  tell application "Script Editor"
    open aliasSaveFilePath
  end tell
end if



|

com.apple.Network-Link-Conditioner

com.apple.Network-Link-Conditionerパネルのオープンは

set strCommandText to "/usr/bin/open '/Library/PreferencePanes/Network Link Conditioner.prefPane'" as text
do shell script strCommandText
-->パス指定が現在は安定感がある
tell application id "com.apple.finder"
  open location "x-apple.systempreferences:com.apple.Network-Link-Conditioner"
end tell

tell application id "com.apple.systempreferences"
reveal anchor "Network Link Conditioner" of pane id "com.apple.Network-Link-Conditioner"
end tell
-->error "System Settingsでエラーが起きました: anchor \"Network Link Conditioner\" of pane id \"com.apple.Network-Link-Conditioner\"を取り出すことはできません。" number -1728 from anchor "Network Link Conditioner" of pane id "com.apple.Network-Link-Conditioner"

set strCommandText to "/usr/bin/open -b com.apple.Network-Link-Conditioner" as text
do shell script strCommandText
-->error "LSCopyApplicationURLsForBundleIdentifier() failed while trying to determine the application with bundle identifier com.apple.Network-Link-Conditioner." number 1

|

[macos14]システム設定収集 macOS14対応版


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#システム設定オープン用のスクリプト作成補助 v3
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

set strBundleID to "com.apple.systempreferences" as text


############################
###【1】システム設定の起動を確定させる
set ocidRunAppArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
if (count of ocidRunAppArray) ≠ 0 then
  log "起動中です"
  tell application id strBundleID to activate
else
  ####ゾンビ対策終了させてから処理させる
  tell application id strBundleID
    set numCntWindow to (count of every window) as integer
  end tell
  if numCntWindow = 0 then
    tell application id strBundleID to quit
  else
    tell application id strBundleID
      close (every window)
      quit
    end tell
  end if
  ####半ゾンビ化対策
  set ocidRunningApplication to refMe's NSRunningApplication
  set ocidAppArray to ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
  repeat with itemAppArray in ocidAppArray
itemAppArray's terminate
  end repeat
  ###システム設定を起動させる
  try
    tell application id strBundleID to activate
  on error
    tell application "System Settings" to activate
  end try
  ###起動待ち
  tell application id strBundleID
    ###起動確認 最大10秒
    repeat 10 times
      activate
      set boolFrontMost to frontmost as boolean
      log boolFrontMost
      if boolFrontMost is true then
###魔法の1秒
delay 0.5
exit repeat
      else
delay 0.5
      end if
    end repeat
  end tell
end if
############################
###【2】全てのパネルのIDを取得
tell application id "com.apple.systempreferences"
  set listPanelID to (id of every pane) as list
end tell

############################
###【A】正順レコード
set ocidPaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###【B】逆順レコード
set ocidReversePaneDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###【3】1で取得したリストの数だけ繰り返し
repeat with itemPanelID in listPanelID
  set strPanelID to itemPanelID as text
  tell application "System Settings"
    set strPanelName to (name of pane id strPanelID) as text
  end tell
  ###【A】正順レコード
  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelName) forKey:(strPanelID))
(ocidPaneDict's addEntriesFromDictionary:(ocidItemDict))
  ###【B】逆順レコード
  set ocidItemDict to (refMe's NSDictionary's dictionaryWithObject:(strPanelID) forKey:(strPanelName))
(ocidReversePaneDict's addEntriesFromDictionary:(ocidItemDict))
end repeat

############################
###【4】ダイアログ用に正順レコードのLISTを作る
set ocidAllValueArray to ocidPaneDict's allValues()
##ソートしておく
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(true) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidDescriptorArray's addObject:(ocidDescriptor)
set ocidSortedKey to (ocidAllValueArray's sortedArrayUsingDescriptors:(ocidDescriptorArray))
set listAllValueArray to ocidSortedKey as list
############################
###【5】ダイアログ  パネル
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
try
  set listResponse to (choose from list listAllValueArray with title "選んでください" with prompt "選択したパネルを開きます" default items (item 1 of listAllValueArray) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
else
  set strResponse to (item 1 of listResponse) as text
end if
log strResponse
############################
###【6】戻り値を逆順リストで検索してパネルIDを取得
set ocidPaneID to ocidReversePaneDict's valueForKey:(strResponse)
set strPaneID to ocidPaneID as text

############################
###【7】アンカーの値の取得
tell application "System Settings"
  set listPaneAnchor to (name of anchors of pane strResponse) as list
  log listPaneAnchor
end tell
############################
###【8】ダイアログ アンカー
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
try
  set listResponse to (choose from list listPaneAnchor with title "選んでください" with prompt "選択したアンカーを開きます" default items (item 1 of listPaneAnchor) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
else
  set strPaneAnchor to (item 1 of listResponse) as text
end if
log strPaneAnchor


############################
###【9】URLにする
set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
###スキーム
ocidURLComponents's setScheme:("x-apple.systempreferences")
###パネルIDをパスにセット
ocidURLComponents's setPath:(ocidPaneID)
###アンカーをクエリーとして追加
ocidURLComponents's setQuery:(strPaneAnchor)
set ocidOpenAppURL to ocidURLComponents's |URL|
set strOpenAppURL to ocidOpenAppURL's absoluteString() as text
log strOpenAppURL

############################
###【10】ワークスペースで開く
###ファイルURLとパネルのURLをArrayにしておく
set ocidOpenUrlArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
ocidOpenUrlArray's insertObject:(ocidOpenAppURL) atIndex:0
###FinderでURLを開くのでFinderのURLを用意
set strBundleID to "com.apple.finder" as text
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidAppPathURL to appShardWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID)
###NSWorkspaceで開く
set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration()
ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true)
ocidOpenConfig's setAllowsRunningApplicationSubstitution:(refMe's NSNumber's numberWithBool:true)
appShardWorkspace's openURLs:(ocidOpenUrlArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value)

####システム設定が前面に来るまで待つ
repeat 20 times
  set boolFrontMost to frontmost of application id "com.apple.systempreferences"
  if boolFrontMost is false then
    tell application id "com.apple.systempreferences" to activate
  else
    exit repeat
  end if
  delay 0.2
end repeat


#################################
###【11】ダイアログ用に値を用意
set strScript to ("#!/usr/bin/env osascript\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\n#com.cocolog-nifty.quicktimer.icefloe\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\nuse AppleScript version \"2.8\"\nuse framework \"Foundation\"\nuse framework \"AppKit\"\nuse framework \"UniformTypeIdentifiers\"\nuse scripting additions\nproperty refMe : a reference to current application\nset strBundleID to \"com.apple.systempreferences\" as text\n###URLにする\nset ocidURLComponents to refMe's NSURLComponents's alloc()'s init()\n###スキーム\nocidURLComponents's setScheme:(\"x-apple.systempreferences\")\n###パネルIDをパスにセット\nocidURLComponents's setPath:(\"" & strPaneID & "\")\n###アンカーをクエリーとして追加\nocidURLComponents's setQuery:(\"" & strPaneAnchor & "\")\nset ocidOpenAppURL to ocidURLComponents's |URL|\nset strOpenAppURL to ocidOpenAppURL's absoluteString() as text\n###ワークスペースで開く\nset appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()\nset boolDone to appShardWorkspace's openURL:(ocidOpenAppURL)\nlog boolDone\nif boolDone is false then\ntell application id \"com.apple.systempreferences\" to activate\ntell application id \"com.apple.systempreferences\"\nreveal anchor \"" & strPaneAnchor & "\" of pane id \"" & strPaneID & "\"\nend tell\ntell application id \"com.apple.finder\"\nopen location \"" & strOpenAppURL & "\"\nend tell\ntell application id \"com.apple.systempreferences\" to activate\nend if\nreturn\n")

#################################
###【12】戻り値ダイアログ
set strName to (name of current application) as text
log strName
if strName is "osascript" then
  repeat 20 times
    set boolFrontMost to frontmost of application "Finder"
    if boolFrontMost is false then
      tell application "Finder" to activate
    else
      exit repeat
    end if
    delay 0.2
  end repeat
else
  repeat 5 times
    set boolFrontMost to frontmost of application "Script Editor"
    log boolFrontMost
    if boolFrontMost is false then
      tell current application to activate
    else
      exit repeat
    end if
    delay 0.2
  end repeat
  
end if
###ダイアログ
set strIconPath to "/System/Library/CoreServices/ManagedClient.app/Contents/PlugIns/ConfigurationProfilesUI.bundle/Contents/Resources/SystemPrefApp.icns"
set aliasIconPath to POSIX file strIconPath as alias
set recordResult to (display dialog "スクリプト戻り値です" with title "【3】スクリプト" default answer strScript buttons {"クリップボードにコピー", "キャンセル", "スクリプトエディタで開く"} default button "スクリプトエディタで開く" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
#################################
###【13】クリップボードにコピー
if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if
#################################
###【14】OK押したらスクリプト生成
if button returned of recordResult is "スクリプトエディタで開く" then
  ##ファイル名
  set strFileName to (strResponse & "." & (ocidPaneID as text) & "." & strPaneAnchor & ".applescript") as text
  ##保存先はスクリプトメニュー
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidLibraryDIrURL to ocidURLsArray's firstObject()
  set ocidScriptDirPathURL to ocidLibraryDIrURL's URLByAppendingPathComponent:("Scripts/Applications/System Settings/Open")
  ###フォルダを作って
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidScriptDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set ocidSaveFilePathURL to ocidScriptDirPathURL's URLByAppendingPathComponent:(strFileName)
  ###スクリプトをテキストで保存
  set ocidScript to refMe's NSString's stringWithString:(strScript)
  ##改行はLFで
  set ocidLFScript to ocidScript's stringByReplacingOccurrencesOfString:("\r") withString:("\n")
  # set ocidEnc to (refMe's NSUTF16LittleEndianStringEncoding)
  # ターミナルからの実行を配慮してUTF8に
  set ocidEnc to (refMe's NSUTF8StringEncoding)
  set listDone to ocidLFScript's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(ocidEnc) |error|:(reference)
  delay 0.5
  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
  ###ターミナルから実行できるように755に
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidSaveFilePathURL's |path|()) |error|:(reference)
  
  
  ###保存したスクリプトを開く
  tell application "Script Editor"
    open aliasSaveFilePath
  end tell
end if



|

より以前の記事一覧

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom