-
Notifications
You must be signed in to change notification settings - Fork 12
/
hide-desktop.py
76 lines (59 loc) · 2.12 KB
/
hide-desktop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# Maintained at https://github.com/liyanage/macosx-shell-scripts/
#
import sys
import os
import re
import argparse
import logging
import Foundation
import subprocess
class Tool(object):
def __init__(self, args):
self.args = args
def run(self):
if self.args.action == 'toggle':
self.toggle()
elif self.args.action == 'show':
self.show()
elif self.args.action == 'hide':
self.hide()
elif self.args.action == 'auto':
self.auto()
def show(self):
self.set_hidden_state(False)
def hide(self):
self.set_hidden_state(True)
def toggle(self):
self.set_hidden_state(not self.is_currently_hidden())
def auto(self):
try:
self.hide()
raw_input('Desktop hidden, hit Return to unhide:\n')
except BaseException:
pass
finally:
self.show()
def set_hidden_state(self, new_state):
if new_state == self.is_currently_hidden():
return
if new_state:
cmd = 'defaults write com.apple.finder CreateDesktop -bool false'.split()
else:
cmd = 'defaults delete com.apple.finder CreateDesktop'.split()
subprocess.check_call(cmd)
subprocess.check_call('killall Finder'.split())
def is_currently_hidden(self):
finder_settings = Foundation.NSUserDefaults.standardUserDefaults().persistentDomainForName_("com.apple.finder")
if 'CreateDesktop' in finder_settings:
return not finder_settings['CreateDesktop']
return False
@classmethod
def main(cls):
action_default = 'auto' if sys.stdout.isatty() else 'toggle'
parser = argparse.ArgumentParser(description='Hide/show Desktop contents, for presentations / screen recordings / screenshots')
parser.add_argument('action', nargs='?', default=action_default, choices=['hide', 'show', 'toggle', 'auto'], help='Action to perform')
args = parser.parse_args()
cls(args).run()
if __name__ == "__main__":
Tool.main()