Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of plugins #137

Draft
wants to merge 100 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
c00bbd5
Add airdrop plugin
Jan 5, 2017
006986b
Add airport plugin
Jan 5, 2017
1e0a7d3
Add debugmode plugin
Jan 5, 2017
febeb9d
Add lightsensor subcommand to display
Jan 5, 2017
ae21fa6
Fix dock pruning so that it always works
Jan 5, 2017
7d0817f
Allow the dock to be completely disabled
Jan 5, 2017
9aba633
Add autohidedelay and autohidespeed to dock
Jan 5, 2017
70759c9
Add magnificationsize to the dock
Jan 5, 2017
0b95915
Add iconsize to the dock
Jan 5, 2017
06bcbab
Add bounce effects to the dock
Jan 5, 2017
a9d1b71
Whitespace
Jan 5, 2017
9d7f6cf
Add active indicators to dock
Jan 5, 2017
1394663
Add helper functions to remove some duplication around reading values
Jan 6, 2017
5f6fdb9
Add more helper functions to remove a bunch of duplication
Jan 6, 2017
f9090f3
Clear more duplication by creating more helpers
Jan 6, 2017
7e09ee0
Add hidden app dimming to the dock
Jan 6, 2017
c448b24
Add only show running to the dock
Jan 6, 2017
db9b798
Add full screen delay to the dock
Jan 6, 2017
e8c6271
Add iTunes notifications to the dock
Jan 6, 2017
0638d9f
Change helpers to converters to be more specific
Jan 6, 2017
724c018
Add keyboard plugin
Jan 6, 2017
883160a
Add tags to gitignore
Jan 6, 2017
07d85d3
Add spotlight plugin
Jan 6, 2017
f153ae8
Add tooltips plugin
Jan 6, 2017
9c41339
Add consistent way of extracting commands/subcommand names
Jan 6, 2017
c7fab51
Add password delay to screensaver
Jan 6, 2017
508218c
Add bannertime to notification
Jan 6, 2017
4259f41
Add mission control
Jan 6, 2017
0c8f545
Add hot corners plugin
Jan 6, 2017
6823062
Add filevault plugin
Jan 6, 2017
aa4f453
Add power plugin
Jan 7, 2017
4c03fb3
Add dashboard plugin
Jan 7, 2017
1b497d0
Add time machine plugin
Jan 7, 2017
dda1338
Add datetime plugin
Jan 7, 2017
c525512
Add locale plugin
Jan 7, 2017
6921e9f
Fix issues with matching 'true' text
Jan 7, 2017
975c1af
Add autobackup and mediakeys to itunes
Jan 7, 2017
0964f8f
Add diskutility plugin
Jan 7, 2017
969f2d7
Add new firewall commands
Jan 7, 2017
6c3057c
Add scrolling plugin
Jan 7, 2017
42a892f
Add diskimages plugin
Jan 7, 2017
d7c22ba
Add appearance plugin
Jan 7, 2017
079b036
Add launchpad plugin
Jan 7, 2017
112c8a0
Add location plugin
Jan 7, 2017
7aa77d7
Syntax changes
Jan 7, 2017
e991c23
Add autologin to user
Jan 7, 2017
5056f38
Add fastuserswitching and guest to user
Jan 7, 2017
7cba97e
Change to using the login_pref_path variable to remove duplication
Jan 7, 2017
28e2265
Add loginattemptsbeforehint to user
Jan 7, 2017
d057ce6
Add showsecure to user
Jan 7, 2017
8a8157b
Add loginpoweroptions to user
Jan 7, 2017
3f7a9f4
Add warn to trash
Jan 7, 2017
091f58e
Change hostname to add a few more places where it needs to change
Jan 7, 2017
9d0e6ce
Add loginmessage to user
Jan 7, 2017
534569b
Add restartonhang to power
Jan 7, 2017
36d9bdc
Add automatic options to update
Jan 7, 2017
d6391fe
Add interval to update
Jan 7, 2017
26fd3a9
Add animations
Jan 7, 2017
6a3244d
Add remotedsstore to finder
Jan 7, 2017
74fb74d
Add defaultusername to network
Jan 7, 2017
10cafe9
Add quitwhenfinished to printer
Jan 7, 2017
5f969d3
Add wakeonethernet and guestaccess to network
Jan 7, 2017
6fff6d1
Alphabetize README
Jan 7, 2017
7967718
Add standbykey to filevault
Jan 7, 2017
6e67119
Add sound plugin
Jan 7, 2017
8bd82ba
Add persistmemory to power
Jan 7, 2017
c801b5c
Add dialogs plugin
Jan 7, 2017
6f81baa
Add dir show and hide
Jan 7, 2017
f8f7fe8
Add tons of new finder capabilities
Jan 8, 2017
6b3a698
Add screencapture plugin
Jan 8, 2017
c70cebd
Add system plugin
Jan 8, 2017
737eea5
Add menubar plugin
Jan 8, 2017
e07d2f1
Add fullscreen plugin
Jan 8, 2017
fb0857a
Add windows plugin
Jan 8, 2017
317dac6
Add hidequicklookondeactivate to finder
Jan 8, 2017
dedcd82
Add remotesharing to disk
Jan 8, 2017
ed06b08
Update usage in docs to be more consistent
Jan 8, 2017
5024887
Allow yes/no combos to include on/off
Jan 8, 2017
23b8360
Fix matching on floats with more than one number
Jan 8, 2017
6d1ddaa
Quote all the things
Jan 8, 2017
5015654
Fix missing imports/command name extraction
Jan 8, 2017
414e980
Fix places where we weren't using our helpers
Jan 8, 2017
c0fb4d3
Fix calls to incorrect defaults helpers
Jan 8, 2017
4662455
Fix issues with commands being called with no arguments
Jan 8, 2017
ada82f9
Change return text to be better
Jan 8, 2017
a62b94e
Add missing sudos
Jan 8, 2017
5f8cd93
Style and nameing changes
Jan 8, 2017
f6631d2
Remove tooltip font stuff which no longer works
Jan 8, 2017
0ad4199
Fix variable and function call bugs
Jan 8, 2017
965cc83
Fix enabled/disabled instead of enable/disable
Jan 8, 2017
1c0df25
Remove wildcards since they aren't very useful
Jan 8, 2017
2a59df2
Docs fix
Jan 8, 2017
2d3e660
Add autoplay to disk
Jan 8, 2017
5bcbddc
Add mouse plugin
Jan 8, 2017
f42677c
Add toggleshortcut to keyboard
Jan 8, 2017
95a8122
Add loginitems plugin
Jan 8, 2017
3deb7af
Fix standby key
Jan 9, 2017
758ee28
Add foldersfirst to finder
Jan 9, 2017
4c938c7
Fix missing subcommand
Jan 9, 2017
6c60ca1
Remove extra 'killall'
Jan 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tags
*.log
.DS_Store
800 changes: 582 additions & 218 deletions Readme.md

Large diffs are not rendered by default.

180 changes: 180 additions & 0 deletions lib/converters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
_mcli_convert_yes_no_to_boolean() {
local choice="$1"

case "${choice}" in
"")
echo ""
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "true"
;;
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "false"
;;
*)
echo "ERROR"
;;
esac
}

_mcli_convert_yes_no_to_on_off() {
local choice="$1"

case "${choice}" in
"")
echo ""
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "on"
;;
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "off"
;;
*)
echo "ERROR"
;;
esac
}

_mcli_convert_yes_no_to_enabled_disabled() {
local choice="$1"

case "${choice}" in
"")
echo ""
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "enabled"
;;
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "disabled"
;;
*)
echo "ERROR"
;;
esac
}

_mcli_convert_yes_no_to_enable_disable() {
local choice="$1"

case "${choice}" in
"")
echo ""
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "enable"
;;
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "disable"
;;
*)
echo "ERROR"
;;
esac
}

_mcli_convert_exit_status_to_enabled_disabled() {
local command="$1"

if eval "${command} &> /dev/null" ; then
echo "enabled"
else
echo "disabled"
fi
}

_mcli_convert_yes_no_to_load_unload() {
local choice="$1"

case "${choice}" in
"")
echo ""
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "load"
;;
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "unload"
;;
*)
echo "ERROR"
;;
esac
}

_mcli_convert_yes_no_to_inverted_boolean() {
local choice="$1"

case "${choice}" in
"")
echo ""
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "false"
;;
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "true"
;;
*)
echo "ERROR"
;;
esac
}

_mcli_convert_yes_no_to_yes_no() {
local choice="$1"

case "${choice}" in
"")
echo ""
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "YES"
;;
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "NO"
;;
*)
echo "ERROR"
;;
esac
}

_mcli_convert_yes_no_to_integer() {
local choice="$1"

case "${choice}" in
"")
echo ""
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "1"
;;
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "0"
;;
*)
echo "ERROR"
;;
esac
}

_mcli_convert_number_to_number() {
local choice="$1"

case "${choice}" in
"")
echo ""
;;
[0-9]*[.][0-9]*)
echo "${choice}"
;;
[0-9]*)
echo "${choice}"
;;
*)
echo "ERROR"
;;
esac
}
137 changes: 137 additions & 0 deletions lib/defaults.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
_mcli_read() {
local domain="$1"
local key="$2"
local sudo="$3"

[ -n "${domain}" ] && [ -n "${key}" ] || return 1
[[ -n "${sudo}" ]] && sudo="sudo"

${sudo} defaults read "${domain}" "${key}" 2> /dev/null
}

_mcli_read_boolean_as_yes_no() {
local value="$(_mcli_read "$@")"

case "${value}" in
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "NO"
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "YES"
;;
esac
}

_mcli_read_number() {
local value="$(_mcli_read "$@")"

echo "${value}"
}

_mcli_read_string() {
local value="$(_mcli_read "$@")"

echo "${value}"
}

_mcli_read_inverted_boolean() {
local value="$(_mcli_read_boolean_as_yes_no "$@")"

if [[ "${value}" == "YES" ]]; then
echo "NO"
elif [[ "${value}" == "NO" ]]; then
echo "YES"
else
echo "ERROR"
fi
}

_mcli_invert_boolean() {
case "$1" in
0|[nN][oO]|[oO][fF][fF]|[fF][aA][lL][sS][eE])
echo "YES"
;;
1|[yY][eE][sS]|[oO][nN]|[tT][rR][rU][eE])
echo "NO"
;;
esac
}

_mcli_defaults_yes_no_to_integer() {
_mcli_defaults_yes_no_to_type "integer" "convert_yes_no_to_integer" "$@"
}

_mcli_defaults_yes_no_to_boolean() {
_mcli_defaults_yes_no_to_type "boolean" "convert_yes_no_to_boolean" "$@"
}

_mcli_defaults_yes_no_to_inverted_boolean() {
local result="$(_mcli_defaults_yes_no_to_type "boolean" "convert_yes_no_to_inverted_boolean" "$@")"

_mcli_invert_boolean "${result}"
}

_mcli_defaults_number() {
local domain="$1"
local key="$2"
local new_value="$3"
local sudo="$4"
local transformed="$(_mcli_convert_number_to_number "${new_value}")"

case "${transformed}" in
[0-9]*[.][0-9]*)
${sudo} defaults write "${domain}" "${key}" -float "${transformed}"
;;
[0-9]*)
${sudo} defaults write "${domain}" "${key}" -int "${transformed}"
;;
esac

_mcli_read_number "${domain}" "${key}"
}

_mcli_defaults_string() {
local domain="$1"
local key="$2"
local new_value="$3"
local sudo="$4"

if [ -n "${new_value}" ]; then
${sudo} defaults write "${domain}" "${key}" -string "${new_value}"
fi

_mcli_read_string "${domain}" "${key}"
}

_mcli_defaults_delete() {
local domain="$1"
local key="$2"
local sudo="$3"

if [ -n "${sudo}" ]; then
${sudo} sh -c "defaults delete '${domain}' '${key}' 2> /dev/null"
else
defaults delete "${domain}" "${key}" 2> /dev/null
fi
}

# shellcheck disable=SC2086
_mcli_defaults_yes_no_to_type() {
local type="$1"
local transformer="$2"
local domain="$3"
local key="$4"
local new_value="$5"
local sudo="$6"
local transformed="$(_mcli_${transformer} "${new_value}")"

if [ -n "${new_value}" ] && [[ "${transformed}" != "ERROR" ]]; then
${sudo} defaults write "${domain}" "${key}" -${type} "${transformed}"
fi

if [[ "${transformed}" != "ERROR" ]]; then
_mcli_read_boolean_as_yes_no "${domain}" "${key}" "${sudo}"
else
echo "ERROR"
fi
}
9 changes: 9 additions & 0 deletions lib/keyboard_shortcuts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_mcli_keyboard_shortcut_toggle(){
local path_to_plistbuddy="/usr/libexec/PlistBuddy"
local keyboard_shortcut_id="$1"
local enabled="$2"
local plist_path="/Users/$(whoami)/Library/Preferences/com.apple.symbolichotkeys.plist"

${path_to_plistbuddy} -c "Delete :AppleSymbolicHotKeys:${keyboard_shortcut_id}:enabled" ${plist_path} 2> /dev/null
${path_to_plistbuddy} -c "Add :AppleSymbolicHotKeys:${keyboard_shortcut_id}:enabled bool ${enabled}" ${plist_path} 2> /dev/null
}
41 changes: 41 additions & 0 deletions plugins/airdrop
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

source "$( dirname "${BASH_SOURCE[0]}" )/../lib/defaults.sh"
source "$( dirname "${BASH_SOURCE[0]}" )/../lib/converters.sh"

declare command="$(basename "$0")"
declare subcommand="$1"

[ $# -gt 0 ] && shift

help(){
cat<<__EOF__
Usage:
m airdrop onlywifi [ YES | NO ] # Whether to allow all interfaces (or only wifi) to be airdropped to

Examples:
m airdrop onlywifi YES
__EOF__
}

onlywifi(){
value="$(_mcli_defaults_yes_no_to_boolean "com.apple.NetworkBrowser" \
"BrowseAllInterfaces" \
"$1")"

echo "${command} ${subcommand}: ${value}"
}

case "${subcommand}" in
help)
help
;;
onlywifi)
onlywifi $@
;;
*)
help
;;
esac

# vim: ts=4 sw=4 softtabstop=4 expandtab
Loading