troycurtisjr Posted April 28, 2019 Posted April 28, 2019 My first (exported) workflow: Do Not Disturb, Limited - Toggle the macOS Do Not Disturb feature, optionally for a specified length of time. I was really inspired by CalmNotifications but I always forgot to toggle it back. Plus, I really wanted the indicator to reflect the current status, which didn't happen when the "set a plist value and kill NotificationCenter" method is used. Releases | Source bivalvegruff and cands 1 1
vitor Posted April 29, 2019 Posted April 29, 2019 The timing on this is fun, as just yesterday I was going to turn on Do Not Disturb and thought “did I add a timer to the feature?” (I was thinking of CoffeeCoffee). I see this method requires setting up a keyboard shortcut. For reference, you can set those up via the command line. I don’t recommend implementing that as part of the Workflow since you shouldn’t be forcing specific shortcuts on user’s machines, but it might be useful to your own setup, or give you an idea to make the process more straightforward (e.g. suggest a shortcut to the user, and auto set it if they agree).
troycurtisjr Posted April 30, 2019 Author Posted April 30, 2019 That is a great tip Vitor! I'm still pretty new to macOS but I'm gathering `defaults` is where a lot of the action is. For workflows with setup, would that typically be another subcomand ("dnd init"), or some kind of dialog on the first run?
vitor Posted April 30, 2019 Posted April 30, 2019 2 hours ago, troycurtisjr said: but I'm gathering `defaults` is where a lot of the action is. Correct. Though unfortunately, new features tend to not have commands for it. I fear we might even lose some that already exist, with OS upgrades. 2 hours ago, troycurtisjr said: For workflows with setup, would that typically be another subcomand ("dnd init"), or some kind of dialog on the first run? Your choice, but a dialog might be too much. I’d have another command and explain it in the README.
Tony D Posted June 15, 2019 Posted June 15, 2019 Trying this out - it does not seem to be moving the toggle in the notifications pane on MacOS - Should it be?
deekim Posted September 24, 2019 Posted September 24, 2019 On 6/15/2019 at 1:52 PM, Tony D said: Trying this out - it does not seem to be moving the toggle in the notifications pane on MacOS - Should it be? You may need to setup the keyboard shortcut described in the README. Also, thanks @troycurtisjr, worked like a charm
bmex63 Posted November 16, 2020 Posted November 16, 2020 It's no longer working for me on Big Sur. Can anyone else confirm, please? Thank you!
Suhvity Posted November 16, 2020 Posted November 16, 2020 Same here. Love this workflow but has stopped working for me in Big Sur. Would love to see if there's a fix for this.
troycurtisjr Posted November 17, 2020 Author Posted November 17, 2020 I'm glad to hear it has been working well previously! I'm not on Big Sur quite yet, so I haven't needed to work through any issues with it. Our IT has recommended holding off upgrading until they finish testing. I'll likely pick a weekend to do it as soon as they give the green light. If in the meantime anyone figures out what is happening, please post here so we can help each other out. A few general thoughts to check. Did the keyboard shortcut get reset/cleared by chance? Perhaps the action is named something else in BigSur and needs to be set to something else? To help with debugging, you can also open the Alfred preferences, go to the workflows panel, and select the Do Not Disturb workflow. Then you can click the little bug at the top left to enable debug mode. You should see a little window pop at the bottom. Then try activating the workflow dnd 5 You should be able to see several bits of output spitting out. Take a look to see if there is any obvious error messages. I've attached an example screenshot (from Catalina though )
bmex63 Posted November 19, 2020 Posted November 19, 2020 (edited) [19:23:12.688] Do Not Disturb, Limited[Script Filter] Queuing argument '' [19:23:12.840] Do Not Disturb, Limited[Script Filter] Script with argv '' finished [19:23:12.842] STDERR: Do Not Disturb, Limited[Script Filter] 2020-11-18 19:23:12.834 defaults[6688:173712] The domain/default pair of (/Users/USERNAME/Library/Preferences/ByHost/com.apple.notificationcenterui, doNotDisturb) does not exist [19:23:12.843] Do Not Disturb, Limited[Script Filter] {"items":[{"title":"Turn it off","subtitle":"Allow notifications again","variables":{"dndDesiredState":"disabled","timeLimitMin":0}}]} [19:23:13.280] Do Not Disturb, Limited[Script Filter] Queuing argument '5' [19:23:13.458] Do Not Disturb, Limited[Script Filter] Script with argv '5' finished [19:23:13.460] STDERR: Do Not Disturb, Limited[Script Filter] 2020-11-18 19:23:13.452 defaults[6694:173735] The domain/default pair of (/Users/USERNAME/Library/Preferences/ByHost/com.apple.notificationcenterui, doNotDisturb) does not exist [19:23:13.461] Do Not Disturb, Limited[Script Filter] {"items":[{"title":"Turn it off","subtitle":"Allow notifications again","variables":{"dndDesiredState":"disabled","timeLimitMin":5}}]} [19:23:16.306] Do Not Disturb, Limited[Script Filter] Processing complete [19:23:16.309] Do Not Disturb, Limited[Script Filter] Passing output '' to Junction [19:23:16.310] Do Not Disturb, Limited[Junction] Processing complete [19:23:16.310] Do Not Disturb, Limited[Junction] Passing output '' to Run Script [19:23:16.387] Do Not Disturb, Limited[Run Script] Processing complete [19:23:16.392] Do Not Disturb, Limited[Run Script] Passing output '' to Run Script [19:23:16.393] Do Not Disturb, Limited[Run Script] Passing output '' to Filter [19:23:16.393] Do Not Disturb, Limited[Filter] Processing complete [19:23:16.394] Do Not Disturb, Limited[Filter] Passing output '' to Delay [19:23:16.414] STDERR: Do Not Disturb, Limited[Run Script] 2020-11-18 19:23:16.407 defaults[6698:173763] The domain/default pair of (/Users/USERNAME/Library/Preferences/ByHost/com.apple.notificationcenterui, doNotDisturb) does not exist [19:23:16.422] Do Not Disturb, Limited[Run Script] Processing complete [19:23:16.422] Do Not Disturb, Limited[Run Script] Passing output 'enabled' to Filter [19:23:16.423] Do Not Disturb, Limited[Filter] Processing complete [19:23:16.424] Do Not Disturb, Limited[Filter] Passing output 'enabled' to Dispatch Key Combo [19:23:16.425] Do Not Disturb, Limited[Dispatch Key Combo] Processing complete [19:23:16.425] Do Not Disturb, Limited[Dispatch Key Combo] Passing output 'enabled' to Post Notification @troycurtisjr thank you for creating the original workflow. I definitely rely on it. Above is the output that you requested. I changed my actual username to USERNAME in the output above. Let me know if I can be of any further assistance. Happy to test any changes. Cheers! Edited November 19, 2020 by bmex63
Send Me Posted November 20, 2020 Posted November 20, 2020 Thank you for posting. I'm having exactly the same error message. Looking forward to a fix; dnd is one of my favs.
troycurtisjr Posted November 21, 2020 Author Posted November 21, 2020 I'm still not on Big Sur and there doesn't appear to be a lot of specifics about this yet, so I'll need to ask you guys to try some things out that I might normally try on my own system. It looks like I may have over specified the command to get the current status. Can you run this command in a terminal to see if it works? defaults -currentHost read com.apple.notificationcenterui doNotDisturb And I'll keep looking for other hints.
Send Me Posted November 21, 2020 Posted November 21, 2020 command defaults -currentHost read com.apple.notificationcenterui doNotDisturb returned 0
troycurtisjr Posted November 22, 2020 Author Posted November 22, 2020 🎉 That's a great sign! Ok one more test, manually enable do not disturb (Option-Click the notification area is the easiest way IMO), and then run the command again. We are hoping that it returns `1` this time!
troycurtisjr Posted November 22, 2020 Author Posted November 22, 2020 Ah rats! Ok I think I'll still change to that but unfortunately it means it won't know when dnd is currently enabled, but it should at least be able to actually enable it and auto disable later. I'll post here when I have an update available.
troycurtisjr Posted November 22, 2020 Author Posted November 22, 2020 On second thought that doesn't really work. After the delay, I need to know what the current state is so that it doesn't get toggled if for some reason it was manually changed before the timeout expires. There has got to be some what to get it in Big Sur but it is going to take some investigation. If you want a quick hack, which will always toggle the state, then you can open the workflow, then open the "External Script" labeled `dndenabled` and replace the contents of the file with this: #!/bin/bash if [ "$desiredState" = "enabled" ] then echo -n "disabled" else echo -n "enabled" fi
vitor Posted November 22, 2020 Posted November 22, 2020 1 hour ago, troycurtisjr said: There has got to be some what to get it in Big Sur On the contrary, it’s quite possible Apple has killed the feature. They’ve been stripping automation features every year. Even this one was always a hacky solution.
dvd Posted November 23, 2020 Posted November 23, 2020 I use this script a lot so I was bummed when it broke. I'm not really a mac scripter so I'm flailing around a bit looking for options. Here's one path for a fix that I've been playing around with: If you go to the Dock and Menu Bar system pref, and then choose Do Not Disturb in the sidebar, you can set it so that the DND icon appears in the menubar when DND is active. Then, you can access that menubar item via Applescript UI scripting. So, that's a hacky way to check DND status. A couple of other things I notice, but don't really know what to do with. There's a Control Center app. Is that new? I don't know if that offers any solutions. Also there's a com.apple.controlcenter.*.plist.
dvd Posted November 23, 2020 Posted November 23, 2020 Forgot to paste some code: tell application "System Events" tell process "Control Center" try if exists menu bar item "Do Not Disturb" of menu bar 1 then display dialog "DND is on" else display dialog "DND is off" end if on error display dialog "error" end try end tell end tell It takes a couple of beats for it to be added/removed from the menubar, so doesn't work if you run it too quick after changing state.
dvd Posted November 23, 2020 Posted November 23, 2020 Me again. I have this working now. I created dndenabled.scpt using the AS pasted below. I then run that from dndenabled.sh using: osascript dndenabled.scpt dndenabled.scpt: tell application "System Events" tell process "Control Center" try if exists menu bar item "Do Not Disturb" of menu bar 1 then return "enabled" else return "disabled" end if on error return null end try end tell end tell
paulw Posted January 15, 2021 Posted January 15, 2021 (edited) @troycurtisjr With help from someone on reddit, I was able to cobble together code that tests for Do Not Disturb status on Big Sur. The plist file ~/Library/Preferences/com.apple.ncprefs contains a plist item dnd_prefs. That item contains a base64-encoded binary plist (bplist). When that is decoded, if DND is enabled, it would look something like this: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>dndDisplayLock</key> <false/> <key>dndDisplaySleep</key> <false/> <key>dndMirrored</key> <false/> <key>facetimeCanBreakDND</key> <false/> <key>repeatedFacetimeCallsBreaksDND</key> <false/> <key>userPref</key> <dict> <key>date</key> <date>2021-01-15T04:35:29Z</date> <key>enabled</key> <true/> <key>reason</key> <integer>1</integer> </dict> </dict> </plist> The presence of the <key>userPref</key> and the <key>enabled</key> within the adjacent <dict></dict> indicate DND is enabled. So the following code produces 1 if DND is enabled, and 0 if it is disabled: #!/bin/zsh dnd_enabled=$(plutil -extract dnd_prefs xml1 -o - ~/Library/Preferences/com.apple.ncprefs.plist | xpath -q -e 'string(//data)' | base64 -D | plutil -convert xml1 - -o - | xpath -q -e 'boolean(//key[text()="userPref"]/following-sibling::dict/key[text()="enabled"])') echo $dnd_enabled Note: there seems to often be a lag time of a few seconds before the result reflects any change to DND. Feel free to incorporate that in your workflow. Edited January 15, 2021 by paulw deanishe, Chris Messina and dvd 3
dvd Posted January 15, 2021 Posted January 15, 2021 @paulw, thank you! Works better than my hacky applescript. paulw 1
troycurtisjr Posted January 16, 2021 Author Posted January 16, 2021 That's a great find @paulw I think I am getting close to doing the update to big sur, probably not this weekend, maybe the next. 😉 I'll incorporate soon!
paulw Posted January 16, 2021 Posted January 16, 2021 Happy to help! I imagine delving into the bplist a bit more would allow you to re-enable the time-limited DND of your workflow, but I haven't looked into it yet.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now