Skip to content

Instantly share code, notes, and snippets.

@michaeldorner
Last active November 2, 2018 16:35
Show Gist options
  • Save michaeldorner/9070eca6b9d524cd5b4c7e9e415e879f to your computer and use it in GitHub Desktop.
Save michaeldorner/9070eca6b9d524cd5b4c7e9e415e879f to your computer and use it in GitHub Desktop.
Toggle the visibility of hidden files in macOS using Python
#!/usr/local/bin/python3
import subprocess
if __name__ == '__main__':
get_command = 'defaults read com.apple.finder AppleShowAllFiles'
current_visibility = subprocess.check_output([get_command], shell=True).decode().strip()
update_command = 'defaults write com.apple.finder AppleShowAllFiles ' + {'True': 'False', 'False': 'True'}[current_visibility] + '; killall Finder;'
subprocess.call([update_command], shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment