« [System Settings]Accessibility系の値のOFF ON(音声コントロール) Toggle voice control on and off | トップページ | 【メモ】Visual Studio Code(Mac版)で文字コードの操作を行ってはいけない理由 »

[System Settings]Accessibility系の値のOFF ONの場合の相違(サウンド出力の切り替え) Toggle sound device between two devices


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004# AccessibilityがONとOFFではWindowの構造が違っている事がポイント
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use scripting additions
008
009tell application id "com.apple.systempreferences"
010  activate
011  set miniaturized of the settings window to false
012end tell
013
014#wait systempreferences
015repeat 10 times
016  tell application id "com.apple.systempreferences"
017    set boolFrontMost to frontmost as boolean
018  end tell
019  if boolFrontMost is true then
020    # one-second prayer after exit
021    delay 1
022    exit repeat
023  else
024    tell application id "com.apple.systempreferences" to activate
025    delay 0.5
026  end if
027end repeat
028
029#set anchor
030tell application id "com.apple.systempreferences"
031  reveal anchor "output" of pane id "com.apple.Sound-Settings.extension"
032end tell
033tell application id "com.apple.systempreferences" to activate
034
035#wait Accessibility
036repeat 10 times
037  tell application id "com.apple.systempreferences"
038    activate
039    tell current pane
040      set strPaneID to id
041    end tell
042  end tell
043  if strPaneID is "com.apple.systempreferences.GeneralSettings" then
044    delay 0.5
045  else if strPaneID is "com.apple.Sound-Settings.extension" then
046    exit repeat
047  end if
048end repeat
049
050#wait Sound
051repeat 10 times
052  tell application id "com.apple.systempreferences"
053    tell front window
054      set strWindowName to name
055    end tell
056  end tell
057  if strWindowName is "サウンド" then
058    exit repeat
059  else
060    delay 0.5
061  end if
062end repeat
063(*
064MacOS15 NOTE
065アクセシビリティ機能がONのときのターゲット属性
066list 2 of splitter group 1 of list 1 of window "Sound"
067
068アクセシビリティ機能がOFFのときのターゲット属性
069group 2 of splitter group 1 of group 1 of window "Sound"
070
071*)
072# system events
073tell application id "com.apple.systempreferences"
074  activate
075  tell application "System Events"
076    tell process "System Settings"
077      #TYPE A
078      try
079        tell outline 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of list 2 of splitter group 1 of list 1 of window "サウンド"
080          repeat with itemNo from 1 to 2 by 1
081            tell row itemNo
082              set recordProperties to properties
083              set boolSelect to selected of recordProperties
084              if boolSelect is false then
085                select
086                exit repeat
087              end if
088            end tell
089          end repeat
090          log "Done type A"
091        end tell
092      on error
093        #TYPE B
094        tell outline 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "サウンド"
095          repeat with itemNo from 1 to 2 by 1
096            tell row itemNo
097              set recordProperties to properties
098              set boolSelect to selected of recordProperties
099              if boolSelect is false then
100                select
101                exit repeat
102              end if
103            end tell
104          end repeat
105          log "Done type B"
106        end tell
107      end try
108    end tell
109    # click
110  end tell
111end tell
AppleScriptで生成しました

|

« [System Settings]Accessibility系の値のOFF ON(音声コントロール) Toggle voice control on and off | トップページ | 【メモ】Visual Studio Code(Mac版)で文字コードの操作を行ってはいけない理由 »

Accessibility」カテゴリの記事