-1

is there a way to disable notifications when program is running on windows?

Thanks!

Ori
  • 567
  • 3
  • 9
  • What do you want to do, what notification's you want to disable –  Jun 07 '21 at 01:44
  • take a screenshot – Ori Jun 07 '21 at 01:53
  • Ok, so you want to take screen snip using ypthon? –  Jun 07 '21 at 01:54
  • I already have a way of doing that but I want to make sure there are no notifications while it takes the screenshot – Ori Jun 07 '21 at 01:58
  • When I saw your query, I didn't find an suitable site. What you can do is turn on focus assist mode. Or refer here: https://stackoverflow.com/questions/55477041/toggling-focus-assist-mode-in-win-10-programmatically/55490319 –  Jun 07 '21 at 02:05
  • Why should anyone help you? you delete all your question after you receive an answer I didn't spend my time answering your question just for you to delete it. If you keep deleting your question, that has answers, people are less likely to help you the next time when you ask one. – Art Jun 07 '21 at 02:07

1 Answers1

0

The web page here shows how to disable notifications by editing the registry.

Given that, it should be possible to use the winreg module to query and set the pertinent key.

Here's some sample code. This does not work for me on my current system, because I don't have my permission levels set to allow it ( I get "PermissionError: [WinError 5] Access is denied" on the winreg.SetValueEx call), so I can't test it, but it should give you some ideas of how to get there. (Modifying the registry will, at a minimum, require running as admin. Last time I needed to do this, I followed the advice at Request UAC elevation from within a Python script? and it worked for me.)

import winreg

app_name = "Microsoft.SkyDrive.Desktop"
notifications_key = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Notifications\\Settings'

keyname = notifications_key + "\\" + app_name

# check its value
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, keyname)
try:
    enabled_setting = winreg.QueryValueEx(regkey, "Enabled")
    notification_enabled = enabled_setting[0] # 1 = enabled; 0 = not enabled
except FileNotFoundError:
    notification_enabled = None
winreg.CloseKey(regkey)
print(f"Enabled value: {notification_enabled}")

# disable notifications
regkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, keyname, winreg.KEY_SET_VALUE)
winreg.SetValueEx(regkey, "Enabled", 0, winreg.REG_DWORD, 0)
winreg.CloseKey(regkey)
codingatty
  • 2,026
  • 1
  • 23
  • 32
  • What OS are you on? I'd assumed Windows because I deal with the notifications annoyances there; but I see now there's no indication of OS in your question. (Note: if asking OS-specific questions, always say what OD you're referring to.) If you *are* on Windows, winreg is part of the standard library, and does not need to be installed. https://docs.python.org/3/library/winreg.html If you're not on Windows, I don't have any info on how to control notifications on that OS. – codingatty Jun 07 '21 at 22:28