This guide shows how to create a GNOME Shell extension that automatically blocks screenshot notifications.
mkdir -p ~/.local/share/gnome-shell/extensions/[email protected]
cd ~/.local/share/gnome-shell/extensions/[email protected]gnome-shell --versionnano metadata.jsonAdd the following content (include your shell version):
{
"uuid": "[email protected]",
"name": "Nuke Screenshot Notifications",
"description": "Auto-destroy screenshot notifications.",
"shell-version": ["42.9", "46","47","48","49"],
"version": 1
}nano extension.jsAdd the following content:
const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray;
let _signals = [];
function _isScreenshotNotification(notif) {
// The text you see in the banner; adjust if your locale differs.
let summary = String(notif.title || '').toLowerCase();
let body = String(notif.bannerBodyText || '').toLowerCase();
return summary.indexOf('screenshot captured') !== -1 ||
body.indexOf('screenshot captured') !== -1;
}
function _hookSource(source) {
// Destroy existing screenshot notifications from this source
source.notifications.forEach(n => {
if (_isScreenshotNotification(n)) {
log('nuke-screenshots: destroying existing screenshot notification');
n.destroy(MessageTray.NotificationDestroyedReason.SOURCE_CLOSED);
}
});
// Destroy new screenshot notifications
let id = source.connect('notification-added', function (_s, n) {
if (_isScreenshotNotification(n)) {
log('nuke-screenshots: destroying new screenshot notification');
n.destroy(MessageTray.NotificationDestroyedReason.SOURCE_CLOSED);
}
});
_signals.push({ source: source, id: id });
}
function enable() {
log('nuke-screenshots: enable()');
// Hook all current sources
Main.messageTray.getSources().forEach(source => {
_hookSource(source);
});
// Hook future sources
let id = Main.messageTray.connect('source-added', function (_tray, source) {
_hookSource(source);
});
_signals.push({ source: Main.messageTray, id: id });
}
function disable() {
log('nuke-screenshots: disable()');
_signals.forEach(sig => {
if (sig.source && sig.id)
sig.source.disconnect(sig.id);
});
_signals = [];
}Press ALT+F2, type r, and press Enter to reload the shell.
Check if the extension is listed:
gnome-extensions list --userCheck for errors:
gnome-extensions info [email protected]If you see "OUT OF DATE", your shell version was entered into metadata.json incorrectly.
gnome-extensions enable [email protected]Verify it is enabled:
gnome-extensions info [email protected]Make sure Status shows: ENABLED
The extension should now block screenshot notifications automatically.