Proper etiquette for asking help with testing scripts?

Howdy folks, pretty new to the forum here and to AppleScript in general. I was referred here by from the Keyboard Maestro forum when he turned me on to Script Debugger and UI Browser.

After some tinkering I came up with a script that checks the DND status using the menu bar icon, and saves it to a variable. It works great for me, but am curious if it works for other people and their setups as well. Since it reads one of the attributes of the menu bar icon, I imagine one of the requisites is to have the menu bar icon actually visible there. So I am wondering what proper etiquette here is to asking others to check my script and let me know if it works, of how it can be improved.

Below is the actual script if anybody wants to see it. Any feedback whatsoever is more than welcome, and apologies in advance if a newbie like me isn’t supposed to post scripts. :smiley:

UPDATED: I made some revisions to the script based on some suggestions.


----------------------------------------------------------
# Author:		Chris Thomerson
# Version:		1.3
# Version History		
#				1.3 (added script to warn if DND icon is not present)
#				1.2 (removed superfluous space from "ControlCenter")
#				1.1 (added if lines to set DNDStatus variable directly from the script)
#				1.0 (Initial script)
# Created:		Saturday, September 4, 2021
# Modified:		Tuesday, September 7, 2021
# macOS:		Big Sur
# Notes:		This script requires your DND icon to be present in the menu bar to work.
#				If the icon is not present, a warning will be saved to the variable
# I claim no responsibility nor guarantee compatibility
# As with any kind of custom scripts, these must be tested thoroughly on each person's device
# May be used and distributed freely
----------------------------------------------------------

tell application "System Events"
	if attribute "AXEnabled" of menu bar item "Do Not Disturb" of menu bar 1 of application process "ControlCenter" exists then
		if value of attribute "AXEnabled" of menu bar item "Do Not Disturb" of menu bar 1 of application process "ControlCenter" is false then
			set DNDStatus to "Disabled"
		else
			set DNDStatus to "Enabled"
		end if
	else
		display dialog "DND icon not present in menu bar, script will not work without it present" giving up after 5
		set DNDStatus to "DNDFailure"
	end if
end tell

DNDStatus

I think it’s ethical to ask users to test your script. Unfortunately, I don’t have an Apple phone to test it. But I can roughly tell you the answer by looking at the script.

I think, it will work on phones with English localization. To localize your scripts to other languages (when GUI scripting), you should check the related posts by @Yvan Koenig, who has the best knowledge in this area.

In this case, most likely you need to localize only “Do Not Disturb” string.

It worked for me in Big Sur when:

  1. I changed application process “Control Center” into application process “ControlCenter” (without space
  2. added the DND icon (= menu item) directly in the menubar, as independent element, otherwise I was getting "System Events got an error: Can’t get menu bar item “Do Not Disturb” of menu bar 1 of application process “ControlCenter”.
    So you want to check for this …

Luciano

I hadn’t even thought about issues with OS set to other languages. I’ll check this out, thank you.

Thanks for catching that superfluous space in Control Center. Odd that it worked for me, but looking at the actual process it is called “ControlCenter” without the space so I removed it just in case.

Could you elaborate a little on what you mean about adding the DND icon directly in the menubar?

If you do not have the DND menu in the menubar (see image link below), the script triggers an error.

But if you do have it, then everything is OK (see image link below):

Maybe should catch this error and ask the user to add the menu icon in the menubar, or use AS to add it … (which I guess is doable).

Ciao
L.

Oh of course! For some reason I read your response as you having added the icon by means of AppleScript itself. But yea, I figured that the DND icon would need to be present in the menu bar for this script to work since it reads it’s attribute. That’s a good idea about adding some script to alert the user if their icon is not present. Thanks!

EDIT: I updated the script in the original post to implement that suggestion you had, thanks again!