UI

[UI]AdobeReaderの環境設定・ユーザー情報を開く


あくまでも参考にしてください

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

サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use scripting additions
008
009tell application "Adobe Acrobat Reader" to activate
010
011tell application id "com.adobe.Reader"
012  tell application "System Events"
013    tell process "AdobeReader"
014      key down {command}
015      keystroke ","
016      key up {command}
017    end tell
018  end tell
019end tell
020tell application id "com.adobe.Reader"
021  tell application "System Events"
022    click static text "ユーザー情報" of row 22 of outline 1 of scroll area 1 of window "環境設定" of application process "AdobeReader"
023    select row 22 of outline 1 of scroll area 1 of window "環境設定" of application process "AdobeReader"
024  end tell
025end tell
AppleScriptで生成しました

|

[UI]システム設定のUI項目を取得する

こちらを参考にした
https://www.sudoade.com/scripting-the-unscriptable-macadmins-2023-presentation/

あくまでも参考にしてください

サンプルソース(参考)
行番号ソース
001(*
002参考スクリプト
003https://stream.lib.utah.edu/
004MacAdmins Slack: @Xirias
005*)
006
007
008###起動
009tell application id "com.apple.systempreferences"
010  # launch launchを使うとストールする事がある
011  activate
012end tell
013###起動待ち
014tell application id "com.apple.systempreferences"
015  ###起動確認 最大10秒
016  repeat 10 times
017    activate
018    set boolFrontMost to frontmost as boolean
019    if boolFrontMost is true then
020      exit repeat
021    else
022      delay 1
023    end if
024  end repeat
025end tell
026###本処理
027tell application id "com.apple.systempreferences"
028  tell application "System Events"
029    tell process "System Settings"
030      tell front window
031        ##全てのエレメントを書き出す
032        set listUIelement to entire contents
033        repeat with itemElement in listUIelement
034          log itemElement
035          tell itemElement
036            properties
037            log role description as text
038          end tell
039        end repeat
040      end tell
041    end tell
042  end tell
043end tell
044
045
AppleScriptで生成しました

|

[Quartz]マウスカーソルの移動

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

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "Quartz"

property refMe : a reference to current application

###移動させたい位置(左上が0x0
set ocidNSpoint to refMe's NSMakePoint(0, 0)

###移動前の位置
set mouseLoc to refMe's NSEvent's mouseLocation()
log mouseLoc

###移動
refMe's CGWarpMouseCursorPosition(ocidNSpoint)

###移動後の位置
set mouseLoc to refMe's NSEvent's mouseLocation()
log mouseLoc

|

[UI]Wi-Fi システム設定

Screencapture_20230324_23_08_032


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



tell application "System Settings" to launch

--システム環境設定が開くのを待つ
repeat
  set doLaunchApp to get running of application "System Settings"
  if doLaunchApp is false then
    delay 1
  else
    exit repeat
  end if
end repeat

open location "x-apple.systempreferences:com.apple.Network-Settings.extension?Wi-Fi"

repeat
  tell application "System Settings"
    tell window 1
      set strWindowName to name as text
    end tell
  end tell
  if strWindowName is "Wi-Fi" then
    exit repeat
  else
    delay 1
  end if
end repeat


tell application "System Settings"
  tell application "System Events" to tell application process "System Settings"
    
    tell window "Wi-Fi"
      tell group 1
        # get properties of every UI element
        tell splitter group 1
          #   get properties of every UI element
          tell group 2
            #   get properties of every UI element
            tell group 1
              #   get properties of every UI element
              tell group 1
                #   get properties of every UI element
                tell scroll area 1
                  #   get properties of every UI element
                  tell group 1
                    get properties of every UI element
                    tell button 1
                      click
                    end tell
                  end tell
                end tell
              end tell
            end tell
          end tell
        end tell
      end tell
    end tell
  end tell
end tell



Screencapture-20230324-231707

|

UI BROWSER

20221031-110035

https://latenightsw.com/freeware/ui-browser/

|

[System Events]モニタの数(システム環境設定のUI)

ボタンの『"ディスプレイ設定…"』の有無で判断つきます

tell application "System Preferences"
activate
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
end tell


tell application "System Preferences"
activate
properties
tell pane id "com.apple.preference.displays"
properties
end tell
end tell


tell application "System Preferences"
activate
properties
tell pane id "com.apple.preference.displays"
properties
end tell
tell window 1
properties
end tell

end tell

tell application "System Preferences"
activate
delay 3
tell application "System Events"
tell process "System Preferences"
activate
get properties of every UI element
tell window "ディスプレイ"
get properties of every UI element
tell button "ディスプレイ設定…"
try
get properties of every UI element
log "デュアルディスプレイで利用中"
click
on error
log "シングルディスプレイで利用中"
end try
end tell
end tell
end tell
end tell
end tell

|

[UI elements]VoiceOverのOFF-ON

UI elementsの基本はこちらを見てください
[System Events]UI elements スクリプティングの基本

ダウンロード - voiceoveronoff.scpt.zip


#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions



####ターゲットのシステム環境設定を開く
tell application "System Preferences"
reveal anchor "Dictation" of pane id "com.apple.preference.universalaccess"
activate
end tell
######ターゲットのパネルIDが取得出来る=開くまで、1秒まって繰り返し
repeat
tell application "System Preferences"
set boolChkOpen to current pane
if boolChkOpen is (pane id "com.apple.preference.universalaccess") then
exit repeat
end if
end tell
delay 1
end repeat
####まずは左側のスクロールエリアにVoiceOverを選択
tell application "System Events"
tell process "System Preferences"
tell window "アクセシビリティ"
tell scroll area 1
tell table 1
tell row 3
select
end tell
end tell
end tell
end tell
end tell
end tell
####右側のチェックボックスをクリックしてON-OFF
tell application "System Events"
tell process "System Preferences"
tell window "アクセシビリティ"
tell group 1
tell checkbox 1
click
end tell
end tell
end tell
end tell
end tell

|

[System Events]マウスキーのOFF ON

[System Events]UI elements スクリプティングの基本1
[System Events]UI elements スクリプティングの基本2 もどうぞ

ダウンロード - os12e3839ee382a6e382b9e382ade383bconoff.scpt.zip

マウスキーには機種依存があります
Macでマウスキーを使用してポインタを制御する
5be1f3dad8864ae6a431773be15b6dee



超順番に設定していますので分かりやすか…と思います。参考まで

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#   パネルの構成にOS依存がありますのでOS12専用
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


------おまじない
tell application "System Events"
launch
activate
end tell



tell application "System Preferences" to launch

--システム環境設定が開くのを待つ
repeat
set doLaunchApp to get running of application "System Preferences"
if doLaunchApp is false then
delay 0.5
else
exit repeat
end if
end repeat

--アクセシビリティのパネルが開くを待つ
repeat
try
tell application "System Preferences"
set current pane to pane "com.apple.preference.universalaccess"
set thePaneID to id of current pane
end tell
on error
delay 0.5
tell application "System Preferences"
set thePaneID to id of current pane
end tell
end try
if thePaneID is "com.apple.preference.universalaccess" then
exit repeat
else
delay 0.5
end if
end repeat

--アンカーを指定する
tell application "System Preferences"
tell current pane
reveal anchor "Mouse"
end tell
end tell

tell application "System Preferences"
activate
tell application "System Events"
tell process "System Preferences"
activate
tell window "アクセシビリティ"
tell scroll area 1
tell table 1
tell row 15
activate
end tell
end tell
end tell
end tell
end tell
end tell
end tell


tell application "System Preferences"
activate
tell application "System Events"
tell process "System Preferences"
activate
tell window "アクセシビリティ"
tell group 1
tell tab group 1 ---"代替コントロール方法"
tell radio button 2
activate
click
end tell
end tell
end tell
end tell
end tell
end tell
end tell
tell application "System Preferences"
activate
tell application "System Events"
tell process "System Preferences"
activate
tell window "アクセシビリティ"
tell group 1
tell tab group 1 ---"代替コントロール方法"

tell checkbox 1
activate
click
end tell
end tell
end tell
end tell
end tell
end tell
end tell

|

[System Events]UI elements スクリプティングの基本

[System Events]UI elements スクリプティングの基本その2へ続きます

UI elements スクリプティングの基本
AppleScriptの辞書(sdef)に記述がない=AppleScriptでコマンド指示出来ない操作で
UI elementsを使った『ユーザーインターフェイス』の操作コマンドで
操作する事が『可能な物もあります』。
UI elementsの取得方法についてです。
UI elementsを取得するツール『UIBrowser』を使った方が早いのですが
ここでは『手動」で取得する方法を説明します
まずは
このコマンドを使って取得していきます。

get properties of every UI element



こちらの記事
[Printer]プリンターの『Printer Proxy』を作成する(macOS12.3対応)
https://quicktimer.cocolog-nifty.com/icefloe/2022/03/post-315101.html の場合を説明しましょう

ダウンロード - ui20elements.zip


まずは『システム環境設定を開いて』『プリンタとファックス』を開きます
そこでスクリプトを実行します

tell application "System Preferences"
activate
tell application "System Events"
tell process "System Preferences"
activate
get properties of every UI element
end tell
end tell
end tell
戻り値はこんな感じ

結果:

{{minimum value:missing value, orientation:missing value, position:{0, 25}, class:window, accessibility description:missing value, role description:"標準ウインドウ", focused:false, title:"プリンタとスキャナ", size:{668, 490}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXWindow", value:missing value, subrole:"AXStandardWindow", selected:missing value, name:"プリンタとスキャナ", description:"標準ウインドウ"}, {minimum value:missing value, orientation:missing value, position:{0, 0}, class:menu bar, accessibility description:missing value, role description:"メニューバー", focused:missing value, title:missing value, size:{1440, 24}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXMenuBar", value:missing value, subrole:missing value, selected:missing value, name:missing value, description:"メニューバー"}, {minimum value:missing value, orientation:missing value, position:{0, 0}, class:UI element, accessibility description:missing value, role description:"top level function row", focused:missing value, title:missing value, size:{685, 30}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXFunctionRowTopLevelElement", value:missing value, subrole:missing value, selected:missing value, name:missing value, description:"top level function row"}}

これは以下を意味しています
_20220316_15_19_35



続いて Class:windowのエレメントを取得していきます

tell application "System Preferences"
activate
tell application "System Events"
tell process "System Preferences"
activate
tell window "プリンタとスキャナ"
tell scroll area 1
get properties of every UI element
end tell
end tell
end tell
end tell
end tell
戻り値は

結果:

{{minimum value:missing value, orientation:missing value, position:{20, 98}, class:outline, accessibility description:missing value, role description:"アウトライン", focused:false, title:missing value, size:{196, 276}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXOutline", value:missing value, subrole:missing value, selected:missing value, name:missing value, description:"アウトライン"}}

ここでわかる事は
左側のエリアは『class:outline』である事になります
_20220316_15_27_44



_20220316_15_25_34


あとはUIの要素を順番に掘り下げます
class:outline

tell application "System Preferences"
activate
tell application "System Events"
tell process "System Preferences"
activate
tell window "プリンタとスキャナ"
tell scroll area 1
tell outline 1
get properties of every UI element
end tell
end tell
end tell
end tell
end tell
end tell

戻り値は

--> {{minimum value:missing value, orientation:missing value, position:{20, 98}, class:row, accessibility description:missing value, role description:"アウトライン行", focused:missing value, title:missing value, size:{196, 24}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXRow", value:missing value, subrole:"AXOutlineRow", selected:false, name:missing value, description:"アウトライン行"}, {minimum value:missing value, orientation:missing value, position:{20, 122}, class:row, accessibility description:missing value, role description:"アウトライン行", focused:missing value, title:missing value, size:{196, 40}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXRow", value:missing value, subrole:"AXOutlineRow", selected:true, name:missing value, description:"アウトライン行"}, {minimum value:missing value, orientation:missing value, position:{20, 162}, class:row, accessibility description:missing value, role description:"アウトライン行", focused:missing value, title:missing value, size:{196, 40}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXRow", value:missing value, subrole:"AXOutlineRow", selected:false, name:missing value, description:"アウトライン行"}, {minimum value:missing value, orientation:missing value, position:{20, 202}, class:row, accessibility description:missing value, role description:"アウトライン行", focused:missing value, title:missing value, size:{196, 40}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXRow", value:missing value, subrole:"AXOutlineRow", selected:false, name:missing value, description:"アウトライン行"}, {minimum value:missing value, orientation:missing value, position:{20, 98}, class:column, accessibility description:missing value, role description:"", focused:missing value, title:missing value, size:{196, 276}, help:missing value, entire contents:{}, enabled:missing value, maximum value:missing value, role:"AXColumn", value:missing value, subrole:missing value, selected:false, name:missing value, description:""}}


ようやく最終的な要素まで辿り着きました
_20220316_15_29_32


こんな感じでUIの『エレメント』を取得して
対象のUIの値を探してClickなりselectなりする事になります

tell application "System Preferences"
activate
tell application "System Events"
tell process "System Preferences"
activate
try
select row 2 of outline 1 of scroll area 1 of window "プリンタとスキャナ"
select button "プリントキューを開く…" of group 1 of window "プリンタとスキャナ"
click button "プリントキューを開く…" of group 1 of window "プリンタとスキャナ"
end try
end tell
end tell
end tell

|

[System Events]UI elements

ダウンロード - ui20elements.scpt.zip



tell application "System Events"
UI elements enabled
end tell



UI elementn : A piece of the user interface of a process

elements

contains actions, attributes, browsers, busy indicators, buttons, checkboxes, color wells, columns, combo boxes, drawers, groups, grow areas, images, incrementors, lists, menus, menu bars, menu bar items, menu buttons, menu items, outlines, pop overs, pop up buttons, progress indicators, radio buttons, radio groups, relevance indicators, rows, scroll areas, scroll bars, sheets, sliders, splitters, splitter groups, static texts, tab groups, tables, text areas, text fields, toolbars, UI elements, value indicators, windows; contained by application, UI elements, windows.

properties

accessibility description (text or missing value, r/o) : a more complete description of the UI element and its capabilities

class (type, r/o) : the class of the UI Element, which identifies it function

description (text or missing value, r/o) : the accessibility description, if available; otherwise, the role description

enabled (boolean or missing value, r/o) : Is the UI element enabled? ( Does it accept clicks? )

entire contents (list of specifier, r/o) : a list of every UI element contained in this UI element and its child UI elements, to the limits of the tree

focused (boolean or missing value) : Is the focus on this UI element?

help (text or missing value, r/o) : an elaborate description of the UI element and its capabilities

maximum value (number or missing value, r/o) : the maximum value that the UI element can take on

minimum value (number or missing value, r/o) : the minimum value that the UI element can take on

name (text, r/o) : the name of the UI Element, which identifies it within its container

orientation (text or missing value, r/o) : the orientation of the UI element

position (list of number or missing value) : the position of the UI element

role (text, r/o) : an encoded description of the UI element and its capabilities

role description (text, r/o) : a more complete description of the UI element's role

selected (boolean or missing value) : Is the UI element selected?

size (list of number or missing value) : the size of the UI element

subrole (text or missing value, r/o) : an encoded description of the UI element and its capabilities

title (text, r/o) : the title of the UI element as it appears on the screen

value (specifier, number, or text) : the current value of the UI element

responds to

click, select, increment, decrement, confirm, pick, cancel.

|

その他のカテゴリー

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 VMware Fusion 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