Giter Club home page Giter Club logo

mac-cleanup-py's Introduction

mac-cleanup-py

PyPI Tests CodeQL JetBrains

๐Ÿงน Python cleanup script for macOS

mac-cleanup-py is a powerful cleanup script for macOS.
This project is a rewrite of the original mac-cleanup-sh rewritten in Python.

๐Ÿš€ Features

mac-cleanup-py helps you:

  1. Empty Trash
  2. Delete unnecessary logs & files
  3. Clear cache

mac-cleanup-demo

๐Ÿ“ฆ Default Modules
  • adobe - Clears Adobe cache files
  • android - Clears Android caches
  • brew - Clears Homebrew cache
  • cacher - Clears Cacher logs
  • chrome - Clears Google Chrome cache
  • composer - Clears composer cache
  • dns_cache - Clears DNS cache
  • docker - Cleanup dangling Docker Images and stopped containers
  • dropbox - Clears Dropbox cache
  • gem - Cleanup any old versions of Gems
  • go - Clears Go cache
  • google_drive - Clears Google Drive caches
  • gradle - Clears Gradle caches
  • inactive_memory - Purge Inactive Memory
  • ios_apps - Cleanup iOS Applications
  • ios_backups - Removes iOS Device Backups
  • java_cache - Removes Java head dumps from home directory
  • jetbrains - Removes logs from PhpStorm, PyCharm etc
  • kite - Deletes Kite logs
  • lunarclient - Removes Lunar Client logs and cache
  • microsoft_teams - Remove Microsoft Teams logs and cache
  • minecraft - Remove Minecraft logs and cache
  • npm - Cleanup npm Cache
  • pnpm - Cleanup pnpm Cache
  • pod - Cleanup CocoaPods Cache Files
  • poetry - Clears Poetry cache
  • pyenv - Cleanup Pyenv-VirtualEnv Cache
  • steam - Remove Steam logs and cache
  • system_caches - Clear System cache
  • system_log - Clear System Log Files
  • trash - Empty the Trash on All Mounted Volumes and the Main HDD
  • wget_logs - Remove Wget logs and hosts
  • xcode - Cleanup Xcode Derived Data and Archives
  • xcode_simulators - Reset iOS simulators
  • yarn - Cleanup yarn Cache
  • telegram - Clear old Telegram Cache

๐Ÿ“ฅ Installation

Using Homebrew

brew tap mac-cleanup/mac-cleanup-py
brew install mac-cleanup-py

Using pip

pip3 install mac-cleanup

๐Ÿ—‘๏ธ Uninstallation

Using Homebrew

brew uninstall mac-cleanup-py
brew untap mac-cleanup/mac-cleanup-py

Using pip

pip3 uninstall mac-cleanup

๐Ÿ’ก Usage Options

Help menu:

$ mac-cleanup -h

usage: mac-cleanup [-h] [-n] [-u] [-c] [-p]

    A Mac Cleanup Utility in Python
    3.0.4
    https://github.com/mac-cleanup/mac-cleanup-py    

options:
  -h, --help         show this help message and exit
  -n, --dry-run      Dry run without deleting stuff
  -u, --update       Update HomeBrew on cleanup
  -c, --configure    Configure default and custom modules
  -p, --custom-path  Specify path for custom modules

๐ŸŒŸ Contributing

Contributions are always welcome!
If you have any ideas, suggestions, or bug reports, feel free to submit an issue or open a pull request.

๐Ÿ“ License

This project is licensed under the Apache-2.0 License.

๐Ÿ‘ Acknowledgements

This project is developed using tools provided by the JetBrains OSS Development Program.

Find out more about their program and how they support open source here.

JetBrains

mac-cleanup-py's People

Contributors

dependabot[bot] avatar efa2d19 avatar wchenonly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mac-cleanup-py's Issues

Permission access

Question
Just run the script for the first time and it requires access to Calendar and Reminders. Why?

Also, the dry run get's stuck:
image

Getting non-zero return after consecutive runs

Describe The Bug

Expected Behaviour: If run mac-cleanup a second time, I should see Removed - 0 MB
Observed Behaviour: Non-zero return after consecutive runs

Version

3.0.4

How To Reproduce

Run mac-cleanup consecutively.

Add force option to usage options in README

Describe The Bug

I basically forgot to update options in README.
Maybe I should add CI for that later ๐Ÿธ

mac-cleanup -h
usage: mac-cleanup [-h] [-n] [-u] [-c] [-p] [-f]

    Python cleanup script for macOS
    Version: 3.0.4
    https://github.com/mac-cleanup/mac-cleanup-py

options:
  -h, --help         show this help message and exit
  -n, --dry-run      Run without deleting stuff
  -u, --update       Update Homebrew on cleanup
  -c, --configure    Open module configuration screen
  -p, --custom-path  Specify path for custom modules
  -f, --force        Accept all warnings

Add a flag to accept all warnings on cleaning

Is your feature request related to a problem? Please describe.

  • In v3.0.0 warning were added, but it's annoying to accept all of them every time.

Describe the solution you'd like

  • Add new flag to force accept all warnings. Like -f and --force

Additional context

  • I'll do it in a bit. If someone will get ahead of me - you're welcome, but write a comment here so we wouldn't do the same stuff twice ๐Ÿธ

Stuck at 'Clearing System Cache Files'

When trying to run the program it stuck at Clearing System Cache Files 0%.
`
$ python3 -m platform

macOS-12.3.1-arm64-arm-64bit

$ mac-cleanup

Clearing System Cache Files... โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 0% -:--:--`

There are no debug keys so cant diagnose what can be wrong.

Rerunning mac-cleanup causes being stuck on Brew Cache

Describe the bug

Rerunning mac-cleanup causes being stuck on Cleaning up Homebrew Cache

How to Reproduce

Steps to reproduce the behavior:

  1. Execute pip3 install mac-cleanup
  2. Run mac-cleanup - ok
  3. Run again mac-cleanup
  4. Stuck on Cleaning up Homebrew Cache

Screenshots

image

Add "Telegram" module to clear old cache

Is your feature request related to a problem? Please describe.

  • Sometimes telegram keeps old cache and it can't be cleaned from the app. Plus it would be convenient to be able to clean it from the cleaner itself.

Describe the solution you'd like

  • Add new default module for Telegram
  • From my old info it being stored in ~/Library/Group Containers/11111111111.ru.keepcoder.Telegram/stable/account-11111111111/postbox/db where 11111111111 - some unique id

Do not require root privileges by default

Hi, I've just installed mac-cleanup-py and configured it to delete just my user-specific caches (~/.android/cache and similar). Even so, the script asks me for password via sudo. From a quick look at the code it seems it automatically uses sudo for every command? https://github.com/mac-cleanup/mac-cleanup-py/blob/main/mac_cleanup/core_modules.py#L64

That seems unfortunate, as it's a good general principle to not escalate privileges unless it's absolutely necessary. And sudo should not be necessary for just deleting files in my own home folder...?

Custom module is not working (maybe bug?)

Describe The Bug

The cleanup code in the custom module is not executed

Version

  • mac-cleanup 3.0.4
  • Python 3.11.7
  • macOS 13.6.3

How To Reproduce

  1. Create a python file and define a cleanup function that should delete a test file
  2. Run mac-cleanup --custom and specify the directory path of the custom module
  3. Run mac-cleanup -n or mac-cleanup.
  4. Check if the test file has been deleted

Minimum example code to reproduce it (based on module_template.py)

"""Custom module template example."""
from mac_cleanup import *

# Do not import any functions at the top level

print("running example") # is printed 

# Get an instance of Collector
clc = Collector()

# You can create lots of modules in one file
def module_example_2():
    print("running example cleanup")
    with clc as unit:
        unit.message("test file")
        unit.add(Path("~/dotfiles/mac-cleanup-module/test").with_prompt("Delete test file?"))

Expected Behavior

Based on example above, directory and files are not deleted and prompt is not shown.

The statement print("running example") is executed, however this print("running example cleanup") statement is never executed

Improve Configuration Message

First off, thanks for you work on this!

Just an idea but I feel like there could be a better configuration message than [?] Active modules:. To someone new it's not incredibly intuitive what this is referring to (I personally thought this was referring to modules I DON'T want to touch).

Maybe something alone the lines of Select the modules you want to clean:?

You could add subtext Warning: Clearing cache files may result in temporary performance changes in some applications. to educate users what this is doing since it's obviously always a little scary to have something deleting files on your computer.

Just some thoughts, I'd be glad to open a PR if you see this as helpful.

Add option to force increasing permissions on dry-run

Is your feature request related to a problem?

When running the dry-run, I noticed it got an output of ~10GB(forgot to screenshot) and after running, it reported cleaning 99GB.
image

Additional Context

What I noticed is that the only difference on the runs is that the actual run asked for my password, so I got investigating the code a bit and this bit of code seems to be the "problem"/masking the difference:

                except (PermissionError, FileNotFoundError):
                    continue

What do you think of adding a option to force it to get all the permissions for dry-run too?

Also great work on this project! Simple and effective โค๏ธ

Not cleaning up a declared amount of data

Question

The dry run returns the following result: "Approx 26.11 GB will be cleaned." After confirming the continuation of the procedure and saying 'yes' to each questions along it, Mac-Cleanup reports about 700 Mb having been deleted. But after re-running the script, it returns the same result: "Approx 26.11 GB will be cleaned." What am I doing wrong?

**spam content here**

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Run Non-Interactive

Question

This is a great utility script! Is there a way to run this utility in a non-interactive manner? I'm trying to use this as a maintenance script that is launched by my RMM platform without the need to choose options (or have the options as arguments on the command line). Thanks!

Add description to modules in configuration screen

Is your feature request related to a problem? Please describe.

  • It's kinda hard to understand what modules will do when you select them. Opening default_modules.py every time isn't the solution here.

Describe the solution you'd like

  • Add some kind of banner on top of the modules selection screen with some info about them. Maybe inquirer has something to offer.

Describe alternatives you've considered

  • Switch from inquirer to something else if implementation would be hard or impossible.

TypeError: 'type' object is not subscriptable

Installed via pip, running I get:

mac-cleanup -h
Traceback (most recent call last):
  File "/Users/rich/.pyenv/versions/3.8.7/bin/mac-cleanup", line 5, in <module>
    from mac_cleanup.cli import main
  File "/Users/rich/.pyenv/versions/3.8.7/lib/python3.8/site-packages/mac_cleanup/cli.py", line 1, in <module>
    from mac_cleanup.utils import CleanUp, cmd, bytes_to_human, catch_exception
  File "/Users/rich/.pyenv/versions/3.8.7/lib/python3.8/site-packages/mac_cleanup/utils.py", line 13, in <module>
    tuple[Type[BaseException]],
TypeError: 'type' object is not subscriptable
python -V
Python 3.8.7

Add module to change "allow to run in background" entries

Hello,

I have some apps that are running in the background. In my specific case, the "Allow in the Background" login items are coming from /Library/LaunchAgents. It would be great to be able to list and delete them in case a user is not interested in having them start up.

Applications that run on Startup
ls -lah /Library/StartupItems

Property list (plist) items running on startup
ls -lah ~ /Library/LaunchAgents
ls -lah /Library/LaunchAgents
ls -lah /Library/LaunchDaemons
ls -lah /System/Library/LaunchDaemons

Applications that launch on User Login
ls -lah /Library/LaunchAgents
ls -lah ~/Library/LaunchAgents
ls -lah /System/Library/LaunchAgents

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.