Tuesday, September 21, 2021

#1 2021-09-04 12:57:09 pm

cdthomer
Member
Registered: 2018-07-31
Posts: 21

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. big_smile

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

Applescript:


----------------------------------------------------------
# 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

Last edited by cdthomer (2021-09-07 08:16:59 am)


Filed under: DnD

Offline

 

#2 2021-09-05 01:11:58 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2038

Re: Proper etiquette for asking help with testing scripts?

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.

Last edited by KniazidisR (2021-09-05 09:37:35 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2021-09-05 02:05:21 am

ldicroce
Member
Registered: 2017-11-25
Posts: 255

Re: Proper etiquette for asking help with testing scripts?

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

Offline

 

#4 2021-09-05 01:13:05 pm

cdthomer
Member
Registered: 2018-07-31
Posts: 21

Re: Proper etiquette for asking help with testing scripts?

KniazidisR wrote:

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.



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

Offline

 

#5 2021-09-05 01:18:20 pm

cdthomer
Member
Registered: 2018-07-31
Posts: 21

Re: Proper etiquette for asking help with testing scripts?

ldicroce wrote:

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



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?

Offline

 

#6 2021-09-07 06:21:27 am

ldicroce
Member
Registered: 2017-11-25
Posts: 255

Re: Proper etiquette for asking help with testing scripts?

cdthomer wrote:

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.
Without-DND.png



But if you do have it, then everything is OK (see image link below):
With-DND.png

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.

Offline

 

#7 2021-09-07 07:01:24 am

cdthomer
Member
Registered: 2018-07-31
Posts: 21

Re: Proper etiquette for asking help with testing scripts?

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!

ldicroce wrote:

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



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

Last edited by cdthomer (2021-09-07 07:50:37 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)