-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add hide-desktop.py as a LaunchBar action
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
launchbar-actions/HideUnhideDesktop.lbaction/Contents/Scripts/hide-desktop.py |
39 changes: 39 additions & 0 deletions
39
launchbar-actions/HideUnhideDesktop.lbaction/Contents/Info.plist
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>ch.entropy.launchbar.action.hide-desktop</string> | ||
<key>CFBundleName</key> | ||
<string>Hide/Unhide Desktop</string> | ||
<key>CFBundleVersion</key> | ||
<string>1.0</string> | ||
<key>LBAbbreviation</key> | ||
<string>hide</string> | ||
<key>LBDescription</key> | ||
<dict> | ||
<key>LBAuthor</key> | ||
<string>Marc Liyanage</string> | ||
<key>LBTwitter</key> | ||
<string>@liyanage</string> | ||
<key>LBWebsiteURL</key> | ||
<string>http://www.entropy.ch</string> | ||
</dict> | ||
<key>LBScripts</key> | ||
<dict> | ||
<key>LBDefaultScript</key> | ||
<dict> | ||
<key>LBResultType</key> | ||
<string>unknown</string> | ||
<key>LBScriptName</key> | ||
<string>hide-desktop.py</string> | ||
</dict> | ||
</dict> | ||
<key>LBTextInputTitle</key> | ||
<string>Shorter Name</string> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright © 2016 Marc Liyanage</string> | ||
</dict> | ||
</plist> |
76 changes: 76 additions & 0 deletions
76
launchbar-actions/HideUnhideDesktop.lbaction/Contents/Scripts/hide-desktop.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |