r/applescript •

[deleted by user]

[deleted] — view deleted post

0 Upvotes

6 comments sorted by

3

u/Son_of_a_Shepherd Nov 04 '22

Nice! Glad that code has been helpful. Connecting and disconnecting sidecar was actually the reason I wrote it in the first place lol

Here is mine, for the same. Just in case anyone has more than one iPad. Won't work if they are name the same though.

use framework "Foundation"

property pane_ids : {|AppleID|:2, |Family|:3, |Wi-Fi|:5, |Bluetooth|:6, |Network|:7, |Notifications|:9, |Sound|:10, |Focus|:11, |Screen Time|:12, |General|:14, |Appearance|:15, |Accessibility|:16, |Control Center|:17, |Siri & Spotlight|:18, |Privacy & Security|:19, |Desktop & Dock|:21, |Displays|:22, |Wallpaper|:23, |Screen Saver|:24, |Battery|:25, |Lock Screen|:27, |Touch ID & Password|:28, |Users & Groups|:29, |Passwords|:31, |Internet Accounts|:32, |Game Center|:33, |Wallet & ApplePay|:34, |Keyboard|:36, |Trackpad|:37, |Printers & Scanners|:38, |Java|:40}

on get_settings_list()
	tell application "System Settings"
		activate
		delay 1
	end tell
	tell application "System Events"
		tell application process "System Settings"
			set row_list to {}
			set row_num to 0
			tell outline 1 of scroll area 1 of group 1 of splitter group 1 of group 1 of window 1
				repeat with r in rows
					set row_num to row_num + 1
					if UI element 1 of r exists then
						tell UI element 1 of r
							repeat with x in UI elements
								if class of x is static text then
									set row_name to name of x as string
									set val to {row_name, row_num}
									copy val to end of row_list
								end if
							end repeat
						end tell
					end if
				end repeat
			end tell
		end tell
	end tell
	return row_list
end get_settings_list

on open_settings_to(settings_pane)
	set pane to current application's NSDictionary's dictionaryWithDictionary:pane_ids
	set pane_index to (pane's valueForKey:settings_pane) as anything
	tell application "System Settings"
		activate
		delay 1
	end tell
	tell application "System Events"
		tell application process "System Settings"
			tell splitter group 1 of group 1 of window 1
				tell outline 1 of scroll area 1 of group 1
					select row pane_index
				end tell
			end tell
		end tell
	end tell
end open_settings_to

on sidecar_connection(ipad_name)
	tell application "System Events"
		tell application process "System Settings"
			tell splitter group 1 of group 1 of window 1
				tell pop up button 1 of group 1 of group 2
					click
					delay 0.5
					set add_display_items to name of menu items of menu 1 as list
					#set add_display_items to item 1 of add_display_items
					log add_display_items
					set sel_item to 0
					set section_break to 0
					repeat with i from 1 to number of items in add_display_items
						if item i of add_display_items = missing value then
							set section_break to i
							exit repeat
						end if
					end repeat
					if section_break = 0 then
						set section_break to 1
					end if
					repeat with i from section_break to number of items in add_display_items
						if item i of add_display_items = ipad_name then
							set sel_item to i
							log sel_item
							exit repeat
						end if
					end repeat
					click menu item sel_item of menu 1
					return sel_item
				end tell
			end tell
		end tell
	end tell
end sidecar_connection

on run {}
	open_settings_to("Displays")
	sidecar_connection('X's iPad')
	quit application "System Settings"
end run

1

u/yalag Apr 04 '24

Hi is there any chance you can update this script to work with sonoma?

1

u/No_Analysis_1817 Feb 28 '23

If you could be so kind, please consider a PR here: https://github.com/ijoseph/connect-sidecar/issues/2

I spent hours¹ doing the code I put in the above repo for Ventura, only to realize that you (and /u/itcouldvebeensogood) have done it better. The satisfaction could have indeed been so good to reap karma and askdifferent points, but alas, it is not to be.

¹boy they do not make those buttons identifiers human-readable, sheesh

1

u/Spare-Marionberry257 Jan 10 '23

Witchcraft! Works perfectly!

1

u/xeybog Feb 27 '23

Been waiting for that for a long time! Thank you a lot

1

u/duhd1993 Apr 11 '23

Is it possible to change it to the Control Center approach?