VenturaのAppleScriptにおけるGUIスクリプティング(バグ)

VenturaのAppleScriptにおいて、ControlCenterをGUIスクリプティングで操作したいが各要素の「nameプロパティ」が全く実装されていないためそれができない。

(Montereyで動作していたスクリプトがVenturaで動作しなくなった。

なお、Musicなど他のアプリケーションではこの問題は発生していない。


一応、フィードバックはしてありますが、何か他に回避手段があればご教示ください。


(検証用スクリプトと実行結果)

set menuDelay to 1
set menuName to 5 --"サウンド"

set devList to {}

tell application "System Events"
	tell application process "ControlCenter"
		tell menu bar 1's menu bar item menuName
			perform action "AXPress"
			(*
				try
					key down {option}
					perform action "AXPress"
					key up {option}
				on error
					key up {option}
				end try
				*)
		end tell
		delay menuDelay
		tell window 1
			set ret to every UI element
			tell group 1's scroll area 1
				set btns to every checkbox
				set devCurrent to ""
				repeat with btn in btns
					btn's name --properties
					(*
					set devName to btn's name
					set devName to my devText(devName, ",")'s item 1
					if btn's value is 1 then set devName to ";" & devName
					set devList's end to devName
					*)
				end repeat
			end tell
		end tell
	end tell
	delay menuDelay
	key code 53
end tell

if (count devList) is 0 then
	set the clipboard to "Nothing"
	return
else
	repeat with n from 1 to (count devList)
		if n is 1 then
			set devStr to devList's item 1
		else
			set devStr to devStr & "," & devList's item n
		end if
	end repeat
	set the clipboard to devStr
	return
end if

on devText(theText, aDelimiter)
	set tmp to AppleScript's text item delimiters
	set AppleScript's text item delimiters to aDelimiter
	set theList to theText's every text item
	set AppleScript's text item delimiters to tmp
	return theList
end devText


tell application "System Events"
	perform action "AXPress" of menu bar item 5 of menu bar 1 of application process "ControlCenter"
		--> action "AXPress" of menu bar item 5 of menu bar 1 of application process "ControlCenter"
	get every UI element of window 1 of application process "ControlCenter"
		--> {group 1 of window "コントロールセンター" of application process "ControlCenter"}
	get every checkbox of scroll area 1 of group 1 of window 1 of application process "ControlCenter"
		--> {checkbox 1 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter", checkbox 2 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter", checkbox 3 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter", checkbox 4 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter", checkbox 5 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"}
	get name of checkbox 1 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> missing value
	get name of checkbox 2 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> missing value
	get name of checkbox 3 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> missing value
	get name of checkbox 4 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> missing value
	get name of checkbox 5 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> missing value
	key code 53
end tell
tell application "Script Editor"
	set the clipboard to "Nothing"
end tell


(MontereyとVenturaのMenu bar itemのプロパティ設定値の相違)

MacBook Pro 16″

投稿日 2022/11/12 12:32

返信
スレッドに付いたマーク ランキングトップの返信

投稿日 2022/12/10 15:49

サウンドデバイスの取得・選択・変更の一連の流れをスクリプトにしてみました。

コントロールセンターを使わなくても、この方法でいけそうです。

システム設定ウインドウが表示されてしまうのは少し目障りですが...

if (system attribute "sys1") is not 13 then return --Ventura限定

open location "x-apple.systempreferences:com.apple.Sound-Settings.extension"
delay 2

tell application "System Settings"
	tell application "System Events" to tell application process "System Settings"
		tell window 1 to tell group 1's splitter group 1's group 2's group 1's scroll area 1's group 2
			click tab group 1's radio button 1 --出力タブ
			tell scroll area 1's table 1
				set RowsList to every row
				set devList to {}
				repeat with i in RowsList
					set devName to i's UI element 1's group 1's static text's name
					if i's selected then set defaultName to devName
					set end of devList to devName
				end repeat
			end tell
		end tell
	end tell
end tell

activate me
set devSel to (choose from list devList default items defaultName with prompt "デバイスを選択して下さい。") as string

tell application "System Settings"
	tell application "System Events" to tell application process "System Settings"
		tell window 1 to tell group 1's splitter group 1's group 2's group 1's scroll area 1's group 2
			click tab group 1's radio button 1 --出力タブ
			tell scroll area 1's table 1
				set RowsList to every row
				set devList to {}
				repeat with i in RowsList
					set devName to i's UI element 1's group 1's static text's name
					if devName contains devSel then
						set i's selected to true
						delay 1
						exit repeat
					end if
				end repeat
			end tell
		end tell
	end tell
	quit
end tell


返信: 6
スレッドに付いたマーク ランキングトップの返信

2022/12/10 15:49 Pajerow への返信

サウンドデバイスの取得・選択・変更の一連の流れをスクリプトにしてみました。

コントロールセンターを使わなくても、この方法でいけそうです。

システム設定ウインドウが表示されてしまうのは少し目障りですが...

if (system attribute "sys1") is not 13 then return --Ventura限定

open location "x-apple.systempreferences:com.apple.Sound-Settings.extension"
delay 2

tell application "System Settings"
	tell application "System Events" to tell application process "System Settings"
		tell window 1 to tell group 1's splitter group 1's group 2's group 1's scroll area 1's group 2
			click tab group 1's radio button 1 --出力タブ
			tell scroll area 1's table 1
				set RowsList to every row
				set devList to {}
				repeat with i in RowsList
					set devName to i's UI element 1's group 1's static text's name
					if i's selected then set defaultName to devName
					set end of devList to devName
				end repeat
			end tell
		end tell
	end tell
end tell

activate me
set devSel to (choose from list devList default items defaultName with prompt "デバイスを選択して下さい。") as string

tell application "System Settings"
	tell application "System Events" to tell application process "System Settings"
		tell window 1 to tell group 1's splitter group 1's group 2's group 1's scroll area 1's group 2
			click tab group 1's radio button 1 --出力タブ
			tell scroll area 1's table 1
				set RowsList to every row
				set devList to {}
				repeat with i in RowsList
					set devName to i's UI element 1's group 1's static text's name
					if devName contains devSel then
						set i's selected to true
						delay 1
						exit repeat
					end if
				end repeat
			end tell
		end tell
	end tell
	quit
end tell


2022/12/09 06:49 Pajerow への返信

無理やり「システム設定>サウンド」からサウンドデバイスを取得するスクリプトを作成してみました。

UI Elementがものすごく奥深い階層になっていて探し出すのに苦労しましたが、なんとか見つけ出すことができました。

on run
	
	tell application "System Settings"
		
		do shell script "open " & "/System/Library/PreferencePanes/Sound.prefPane"
		delay 1
		
		tell application "System Events"
			tell application process "System Settings"
				tell window 1
					tell group 1's splitter group 1
						tell group 2's group 1's scroll area 1's group 2
							click tab group 1's radio button 1 --出力タブ
							tell scroll area 1's table 1
								set RowsList to every row
								set devList to {}
								repeat with i in RowsList
									tell i's UI element 1's group 1's static text
										set devName to name
										set end of devList to devName
									end tell
								end repeat
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
		
		quit
		
	end tell
	
	if (count devList) is 0 then
		set devStr to "Nothing"
	else
		repeat with n from 1 to (count devList)
			if n is 1 then
				set devStr to devList's item 1
			else
				set devStr to devStr & "," & devList's item n
			end if
		end repeat
	end if
	
end run

2022/11/12 20:34 Pajerow への返信

Ventura は未導入なので試すことができませんが、画像を見る限り title と name は accessibility description と description に引っ越したような印象ですね。以下のようにフィルタを使ってみてはどうでしょうか?


# Monterey

tell application "System Events"
    tell application process "ControlCenter"
        tell menu bar 1's menu bar item "サウンド"
            click
        end tell
    end tell
end tell


# Ventura

tell application "System Events"
    tell application process "ControlCenter"
        tell (menu bar 1's first menu bar item where its accessibility description = "サウンド")
            click
        end tell
    end tell
end tell

2022/11/12 21:15 Hiro__S への返信

Hiro__S さん、こんにちは。

いつもありがとうございます。


お提示いただいたフィルタ設定で、メニューバーボタンの名前指定でのクリックはできました。

「where its」を知らず、今まで「whose」とやってしまっていたのでダメだったようです。

こんな感じです。


次に、出力のデバイス名をリストで取得したいのですが...

しかし、”出力”配下の各要素(checkbox)については、判別できる情報が全く設定されていないのでどうにもなりません。


(検証用スクリプトと実行結果)

tell application "System Events"
	tell application process "ControlCenter"
		tell (menu bar 1's first menu bar item where its description = "サウンド")
			perform action "AXPress"
		end tell
		delay 2
		tell window 1
			set ret to every UI element
			tell group 1's scroll area 1
				set btns to every checkbox
				set devCurrent to ""
				repeat with btn in btns
					btn's properties
				end repeat
			end tell
		end tell
	end tell
end tell


tell application "System Events"
	perform action "AXPress" of menu bar item 1 of menu bar 1 of application process "ControlCenter" whose description = "サウンド"
		--> action "AXPress" of menu bar item 5 of menu bar 1 of application process "ControlCenter"
	get every UI element of window 1 of application process "ControlCenter"
		--> {group 1 of window "コントロールセンター" of application process "ControlCenter"}
	get every checkbox of scroll area 1 of group 1 of window 1 of application process "ControlCenter"
		--> {checkbox 1 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter", checkbox 2 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter", checkbox 3 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter", checkbox 4 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter", checkbox 5 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"}
	get properties of checkbox 1 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> {minimum value:missing value, orientation:missing value, position:{1346, 136}, class:checkbox, accessibility description:missing value, role description:"切り替えボタン", focused:missing value, title:missing value, size:{288, 32}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:1, subrole:"AXToggle", selected:missing value, name:missing value, description:"切り替えボタン"}
	get properties of checkbox 2 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> {minimum value:missing value, orientation:missing value, position:{1346, 168}, class:checkbox, accessibility description:missing value, role description:"切り替えボタン", focused:missing value, title:missing value, size:{288, 32}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:0, subrole:"AXToggle", selected:missing value, name:missing value, description:"切り替えボタン"}
	get properties of checkbox 3 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> {minimum value:missing value, orientation:missing value, position:{1346, 200}, class:checkbox, accessibility description:missing value, role description:"切り替えボタン", focused:missing value, title:missing value, size:{288, 32}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:0, subrole:"AXToggle", selected:missing value, name:missing value, description:"切り替えボタン"}
	get properties of checkbox 4 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> {minimum value:missing value, orientation:missing value, position:{1346, 232}, class:checkbox, accessibility description:missing value, role description:"切り替えボタン", focused:missing value, title:missing value, size:{288, 32}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:0, subrole:"AXToggle", selected:missing value, name:missing value, description:"切り替えボタン"}
	get properties of checkbox 5 of scroll area 1 of group 1 of window "コントロールセンター" of application process "ControlCenter"
		--> {minimum value:missing value, orientation:missing value, position:{1346, 264}, class:checkbox, accessibility description:missing value, role description:"切り替えボタン", focused:missing value, title:missing value, size:{288, 32}, help:missing value, entire contents:{}, enabled:true, maximum value:missing value, role:"AXCheckBox", value:0, subrole:"AXToggle", selected:missing value, name:missing value, description:"切り替えボタン"}
end tell


2022/11/12 22:57 Hiro__S への返信

でしょう? (^^)

テキストがきちんと表示されているのでなんとかそれを取得できないかと思ったのですが...

まぁ、自分でクリックすればいいだけの話なので困りはしませんけど。

Alfredにどっぷりとハマっているので、すべてキーボードで操作すべく奮闘中。


Venturaでは「システム設定」のインターフェイスがこれまで(本当に)長い間慣れ親しんできた「システム環境設定」から大きく変更されてしまったので。これをGUIスクリプティングで操作するというのが実質不可能になってしまったのが痛いですね。

マウスなどで操作するにしても、文字が小さい上にメニューが再配置され、さらに階層が深くなったので必要な項目を探し出すのが大変です。

2022/11/12 22:44 Pajerow への返信

次に、出力のデバイス名をリストで取得したいのですが...
しかし、”出力”配下の各要素(checkbox)については、判別できる情報が全く設定されていないのでどうにもなりません。

(検証用スクリプトと実行結果)
__省略__


あらら、確かにこれではどうにもなりませんね。Apple による改善を待つしかなさそうです...。


このスレッドはシステム、またはAppleコミュニティチームによってロックされました。 問題解決の参考になる情報であれば、どの投稿にでも投票いただけます。またコミュニティで他の回答を検索することもできます。

VenturaのAppleScriptにおけるGUIスクリプティング(バグ)

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple Account を使ってご参加ください。