Created
January 2, 2026 16:00
-
-
Save erfanium/d0562c73a5c3cfdeb9a2b2b4a95e7f03 to your computer and use it in GitHub Desktop.
Script to remove all non-flatpak *.desktop files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import argparse | |
| import shutil | |
| from pathlib import Path | |
| SYS_APPS = Path("/usr/share/applications") | |
| USER_APPS = Path.home() / ".local/share/applications" | |
| FLATPAK_EXPORTS = Path("/var/lib/flatpak/exports/share/applications") | |
| FLATPAK_USER_EXPORTS = Path.home() / ".local/share/flatpak/exports/share/applications" | |
| def is_flatpak_app(desktop_name: str) -> bool: | |
| return ( | |
| (FLATPAK_EXPORTS / desktop_name).exists() | |
| or (FLATPAK_USER_EXPORTS / desktop_name).exists() | |
| ) | |
| def ensure_nodisplay(desktop_path: Path, dry_run: bool): | |
| if dry_run: | |
| print(f"[DRY-RUN] Would ensure NoDisplay=true in: {desktop_path.name}") | |
| return | |
| content = desktop_path.read_text(errors="ignore").splitlines() | |
| new_content = [] | |
| replaced = False | |
| for line in content: | |
| if line.startswith("NoDisplay="): | |
| new_content.append("NoDisplay=true") | |
| replaced = True | |
| else: | |
| new_content.append(line) | |
| if not replaced: | |
| new_content.append("NoDisplay=true") | |
| desktop_path.write_text("\n".join(new_content) + "\n") | |
| print(f"Hidden: {desktop_path.name}") | |
| def main(): | |
| parser = argparse.ArgumentParser( | |
| description="Hide non-Flatpak GNOME apps by adding NoDisplay=true" | |
| ) | |
| parser.add_argument( | |
| "--dry-run", | |
| action="store_true", | |
| help="Show what would be changed without modifying files", | |
| ) | |
| args = parser.parse_args() | |
| USER_APPS.mkdir(parents=True, exist_ok=True) | |
| for desktop in SYS_APPS.glob("*.desktop"): | |
| name = desktop.name | |
| if is_flatpak_app(name): | |
| continue | |
| target = USER_APPS / name | |
| if not target.exists(): | |
| if args.dry_run: | |
| print(f"[DRY-RUN] Would copy: {name}") | |
| else: | |
| shutil.copy2(desktop, target) | |
| if target.exists() or args.dry_run: | |
| ensure_nodisplay(target, args.dry_run) | |
| print("\nDone.") | |
| if args.dry_run: | |
| print("No files were modified.") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment