Apple Script error

This forum is a place to post questions about doing things that aren't necessarily Indigo specific (though they could be). For instance:
  • How do I automate the following HTTP POST?
  • How can I restart my router periodically?
  • How can I do whole house audio?

ELWOOD
Posts: 230
Joined: Sun Feb 11, 2007 12:15 pm
Location: Ramsey, NJ

Apple Script error

Post by ELWOOD »

Moved my server to a new computer a few months back, all went very smoothly. Just updated it's OS from 12.7.6 to 13.6.8 and am now getting errors on an apple script i used to change the audio output on the server computer. Looks like there is a difference with system settings and system preferences with OS 13.6, has a new layout, figure this may be my problem, The old script will compile with no errors. When I run it shows and error .

This is when i compile with no error showing:

script error audio switch.jpg
script error audio switch.jpg (54.2 KiB) Viewed 583 times


This is when I run and it gives the error
script error audio switch 2.jpg
script error audio switch 2.jpg (59.71 KiB) Viewed 583 times
I know very little about writing apple script so if any one who can help it would be greatly appreciate

Thanks
Elwood
User avatar
jay (support)
Site Admin
Posts: 18376
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Apple Script error

Post by jay (support) »

[MODERATOR NOTE]: moved to a more appropriate forum since Indigo doesn't directly support AppleScript.

Sorry, I have no idea how to do that. I'd recommend Googling it to see if there are any hits.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
CliveS
Posts: 778
Joined: Sun Jan 10, 2016 5:31 am
Location: Medomsley, County Durham, UK

Re: Apple Script error

Post by CliveS »

I know nothing about AppleScript but I put your message into ChatGPT (it can be wrong but I use it for correcting and optimising my Python code with great success ) and it came back with the following

Your message pasted into ChatGPT
Moved my server to a new computer a few months back, all went very smoothly. Just updated its OS from 12.7.6 to 13.6.8 and am now getting errors on an apple script i used to change the audio output on the server computer. Looks like there is a difference with system settings and system preferences with OS 13.6, has a new layout, figure this may be my problem, The old script will compile with no errors. When I run it shows and error . This is when i compile with no error showing
ChatGPT said:

With the update to macOS 13 (Ventura), "System Preferences" was renamed to "System Settings," and the layout and internal structure have changed, which is likely the cause of the issues you're encountering with your AppleScript.
Updated Script for macOS Ventura (13.x):
Here's an updated version of the script that should work with macOS Ventura:
applescript

Code: Select all

-- Used to select sound output for either the Samsung audio (turn on when using Kodi app for movies) or USB advanced audio device (Normet set for announcements through house speakers)

set outputA to 1 -- (Samsung DisplayPort) Change this to the actual 'line number' of your first desired output (check the listed order in the 'System' preference 'Sound' the output order may change if output devices are added or removed from computer)
set outputB to 2 -- (USB Advanced Audio Device USB) Change this to the actual 'line number' of your second desired output
-- The rest of the script will use these values as a switch

try
	-- Open the Sound preferences pane in System Settings
	tell application "System Settings"
		activate
		reveal anchor "output" of pane id "com.apple.preference.sound"
	end tell

	-- Wait until the Sound pane is fully loaded and select the output device
	tell application "System Events"
		tell process "System Settings"
			repeat until exists tab group 1 of window 1
			end repeat
			tell tab group 1 of window 1
				click radio button "Output"
				set selected of row outputB of table 1 of scroll area 1 to true
			end tell
		end tell
	end tell

	-- Close System Settings
	tell application "System Settings" to quit

on error errMsg number errNum
	-- Display an error dialog with the message and number
	display dialog "Error: " & errMsg & " (" & errNum & ")" buttons {"OK"} default button 1
end try
Explanation of Changes:
1. System Settings vs. System Preferences: The script now references System Settings to match the new macOS naming convention.
2. Anchor Use: The reveal anchor "output" of pane id "com.apple.preference.sound" command is used to directly target the Output tab in the Sound preferences pane.
3. Error Handling: The try...on error block will catch any errors and display a dialog with the error message and number, helping with troubleshooting.
Notes:
* Row Number: The line set selected of row 2 of table 1 of scroll area 1 to true may need to be adjusted depending on which row corresponds to the desired audio output device in the list. If the device is not in the second row, you should change the 2 to the appropriate row number.
* Compatibility: This script assumes you're on macOS 13.x (Ventura). If you're using a different version, the structure might still vary slightly.
Testing:
Try running this updated script and see if it resolves the issue on your server. If you encounter any errors, the error handling will provide more detailed information that can help further troubleshoot the problem.

Hope this cures the error.
CliveS

Indigo 2023.2.0 : macOS Sonoma 14.6.1 : Mac Mini M2 : 8‑core CPU and 10‑core GPU : 8 GB : 256GB SSD

The best way to get the right answer on the Internet is not to ask a question, it's to post the wrong answer
ELWOOD
Posts: 230
Joined: Sun Feb 11, 2007 12:15 pm
Location: Ramsey, NJ

Re: Apple Script error

Post by ELWOOD »

Thanks CliveS for your reply,

Still getting errors and I think it's still related to changing from 12.6 to 13.6 and the change in settings. When I would run the original script on 12,6 you can see the script open systems settings with sound and correctly selects the correct output,

With the new script on 13,6 I get two different results: with system settings off and running the script it opens systems settings at Appearance pane, the script shows running and I need to hit stop to end it. That shows error user cancelled.

Running it again but first open systems settings to Sound pane the script shows error : Error: System Settings got an error: Can’t get pane id "com.apple.preference.sound". (-1728) and result shows: {button returned:"OK"}

So any ideas would be great


Elwood
Post Reply

Return to “How Do I...”