Created
March 26, 2023 17:26
-
-
Save jmcerrejon/bb0f8b1884c7b431460d2c1b564f6200 to your computer and use it in GitHub Desktop.
Clean macOS volumes for non mac OS
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 subprocess | |
def main(): | |
volumes = subprocess.run(['mount'], stdout=subprocess.PIPE).stdout.decode('utf-8').split('\n') | |
for volume in volumes: | |
if '/Volumes/' in volume and 'nodev' in volume: | |
volume_name = volume.split()[2] | |
clean_volume(f"{volume_name}/pelis" if os.path.isdir(f"{volume_name}/pelis") else f"{volume_name}") | |
unmount_volume(volume_name) | |
def clean_volume(volume_name): | |
print(f"\nFound: {volume_name}. Cleaning...") | |
subprocess.run(["rm", "-rf", f"{volume_name}/.Trashes"]) | |
subprocess.run(["rm", "-rf", f"{volume_name}/.fseventsd"]) | |
subprocess.run(["rm", "-rf", f"{volume_name}/.Spotlight-V100"]) | |
subprocess.run([f"find", volume_name, "-type", "f", "-name", "._*", "-depth", "-delete"]) | |
subprocess.run([f"find", volume_name, "-type", "f", "-name", ".DS*", "-depth", "-delete"]) | |
def unmount_volume(volume_name): | |
print(f"\nUnmounting: {volume_name}") | |
subprocess.run(["diskutil", "unmountDisk", f"{volume_name}"]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment