Skip to content

Instantly share code, notes, and snippets.

@av1d
Created December 24, 2025 05:22
Show Gist options
  • Select an option

  • Save av1d/0518c4506429c89cc20fdc6b1e9bfa8b to your computer and use it in GitHub Desktop.

Select an option

Save av1d/0518c4506429c89cc20fdc6b1e9bfa8b to your computer and use it in GitHub Desktop.
Block Screenshot Notifications in GNOME

Block Screenshot Notifications in GNOME

This guide shows how to create a GNOME Shell extension that automatically blocks screenshot notifications.

Step 1: Create Extension Directory

mkdir -p ~/.local/share/gnome-shell/extensions/[email protected]
cd ~/.local/share/gnome-shell/extensions/[email protected]

Step 2: Check GNOME Shell Version

gnome-shell --version

Step 3: Create metadata.json

nano metadata.json

Add 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
}

Step 4: Create extension.js

nano extension.js

Add 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 = [];
}

Step 5: Reload GNOME Shell

Press ALT+F2, type r, and press Enter to reload the shell.

Step 6: Verify Extension

Check if the extension is listed:

gnome-extensions list --user

Check for errors:

gnome-extensions info [email protected]

If you see "OUT OF DATE", your shell version was entered into metadata.json incorrectly.

Step 7: Enable Extension

gnome-extensions enable [email protected]

Verify it is enabled:

gnome-extensions info [email protected]

Make sure Status shows: ENABLED

Done

The extension should now block screenshot notifications automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment