AppleScript UI

[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.

|

その他のカテゴリー

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