システム環境設定の「ディスプレイ」paneの「ディスプレイ」を表示するAppleScriptです。
やりかたは山のようにあるものの、Cocoa系の機能を使うとこんな感じ。
AppleScript名:システム環境設定の「ディスプレイ」>「ディスプレイ」を表示_asobjc.scptd |
— – Created by: Takaaki Naganoya – Created on: 2020/04/28 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use framework "AppKit" use scripting additions current application’s NSWorkspace’s sharedWorkspace()’s openFile:"/System/Library/PreferencePanes/Displays.prefPane" |
まんま、同じ内容をshell呼び出しで書くとこんな感じ。
AppleScript名:システム環境設定の「ディスプレイ」>「ディスプレイ」を表示_shell.scptd |
— – Created by: Takaaki Naganoya – Created on: 2020/04/28 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions do shell script "open /System/Library/PreferencePanes/Displays.prefPane" |
System Events経由でファイルオープンするとこんな感じ。POSIX pathをfileとして指定できて驚きました。aliasにcastしないとopenできないかと思っていました。
AppleScript名:システム環境設定の「ディスプレイ」>「ディスプレイ」を表示_System Events.scptd |
— – Created by: Takaaki Naganoya – Created on: 2020/04/28 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions tell application "System Events" open file "/System/Library/PreferencePanes/Displays.prefPane" end tell |
AppleScript的にいろいろルーチンを整備して汎用性を持たせつつ、十分な機能を用意するとこんな感じでしょうか。
AppleScript名:システム環境設定の「ディスプレイ」>「ディスプレイ」を表示 |
— Created 2017-10-10 by Takaaki Naganoya — Created 2020-04-28 by Takaaki Naganoya — 2020 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –Get every pane ID set aList to getEveryPaneID() of me –Get every anchor in a pane set pList to getEveryAnchorName("com.apple.preference.displays") of me –> {"displaysArrangementTab", "displaysNightShiftTab", "displaysColorTab", "displaysGeometryTab", "displaysDisplayTab"} set aRes to dispSystemPreferences("com.apple.preference.displays", "displaysDisplayTab") of me –> true on dispSystemPreferences(paneID, anchorID) tell application "System Preferences" activate set pList to id of every pane if paneID is not in pList then return false set current pane to pane paneID tell current pane set nList to name of every anchor if anchorID is not in nList then return false reveal anchor anchorID end tell end tell return true end dispSystemPreferences on getEveryPaneID() tell application "System Preferences" return id of every pane end tell end getEveryPaneID on getEveryAnchorName(paneID) tell application "System Preferences" set pList to id of every pane if paneID is not in pList then return false set current pane to pane paneID tell current pane return name of every anchor end tell end tell end getEveryAnchorName |
More from my site
(Visited 113 times, 1 visits today)