Skip to content

Commit 76cada0

Browse files
authored
Merge pull request #129 from unixorn/add-more-darwin-checks
Tidy up scripts
2 parents 0e016d3 + ae0fea1 commit 76cada0

31 files changed

+158
-11
lines changed

bin/battery-percentage

+3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
set -o pipefail
17+
1618
if [[ "$(uname -s)" != 'Darwin' ]]; then
1719
echo 'Sorry, this script only works on macOS'
1820
exit 1
1921
fi
2022

2123
# Print battery percentage
2224
pmset -g batt | grep -E "([0-9]+\%).*" -o --colour=auto | cut -f1 -d';'
25+
exit $?

bin/battery-time

+3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
set -o pipefail
17+
1618
if [[ "$(uname -s)" != 'Darwin' ]]; then
1719
echo 'Sorry, this script only works on macOS'
1820
exit 1
1921
fi
2022

2123
# Print system's estimate of battery time remaining
2224
pmset -g batt | grep -E "([0-9]+\%).*" -o --colour=auto | cut -f3 -d';'
25+
exit $?

bin/charger-wattage

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22
#
3-
# Script skeleton
3+
# Show the wattage of your charger
44
#
5-
# Copyright 2021, Your Name <[email protected]>
5+
# Copyright 2021, Joe Block <[email protected]>
66

77
set -o pipefail
88
if [[ -n "$DEBUG" ]]; then

bin/clean-xml-clip

+11
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,15 @@ if [[ "$(uname -s)" != 'Darwin' ]]; then
1111
exit 1
1212
fi
1313

14+
function has() {
15+
# Check if a command is in $PATH
16+
which "$@" > /dev/null 2>&1
17+
}
18+
19+
if ! has tidy; then
20+
echo 'tidy not found in $PATH!'
21+
exit 13
22+
fi
23+
1424
pbpaste | tidy -xml -wrap 0 | pbcopy
25+
exit $?

bin/column-view

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if [[ "$(uname -s)" != 'Darwin' ]]; then
2121
exit 1
2222
fi
2323

24-
osascript <<EOT
24+
exec osascript <<EOT
2525
set cwd to do shell script "pwd"
2626
tell application "Finder"
2727
if (${1-1} <= (count Finder windows)) then

bin/diceware-password

+17-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ STR
8585
@num_rounds.times do
8686
ary = [random_word, random_special, random_word, random_special, random_word]
8787
phrase = ary.join('')
88-
88+
8989
phrase = munge_case(phrase) if @case
9090

9191
phrases << phrase
@@ -7875,4 +7875,19 @@ __END__
78757875
66663 =
78767876
66664 ?
78777877
66665 ??
7878-
66666 @
7878+
66666 @
7879+
66667 ziggurat
7880+
66668 godzilla
7881+
66669 rodan
7882+
66670 gammera
7883+
66671 ultraman
7884+
66672 cthulhu
7885+
66673 shoggoth
7886+
66674 mordor
7887+
66675 gandalf
7888+
66676 frodo
7889+
66677 boromir
7890+
66678 saruman
7891+
66679 balrog
7892+
66680 elboreth
7893+
66681 yendor

bin/disable-bouncing-dock-icons

+5
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66

77
set -o pipefail
88

9+
if [[ "$(uname -s)" != 'Darwin' ]]; then
10+
echo 'Sorry, this script only works on macOS'
11+
exit 1
12+
fi
13+
914
defaults write com.apple.dock no-bouncing -bool TRUE
1015
killall Dock

bin/disable-crash-reports

+5
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
#
55
# Copyright 2023, Joe Block <[email protected]>
66

7+
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
echo 'Sorry, this script only works on macOS'
9+
exit 1
10+
fi
11+
712
echo "You can re-enable crash reports with 'enable-crash-reports'"
813
exec defaults write com.apple.CrashReporterDialogType none

bin/disable-network-ds-store-files

+5
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
#
55
# Copyright 2020, Joe Block <[email protected]>
66

7+
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
echo 'Sorry, this script only works on macOS'
9+
exit 1
10+
fi
11+
712
exec defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE

bin/disturb

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
set -o pipefail
88

9+
if [[ "$(uname -s)" != 'Darwin' ]]; then
10+
echo 'Sorry, this script only works on macOS'
11+
exit 1
12+
fi
13+
914
#
1015
# Based on an answer by Jacques Rioux on discussions.apple.com.
1116
#

bin/dns-resolvers

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ set -o pipefail
88

99
case $(uname) in
1010
Darwin)
11-
exec scutil --dns | awk '/^(DNS|resolver| (search|nameserver|domain))/'
11+
scutil --dns | awk '/^(DNS|resolver| (search|nameserver|domain))/'
12+
exit $?
1213
;;
1314
Linux)
1415
exec cat /etc/resolv.conf

bin/do-not-disturb

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
# Based on an answer by Jacques Rioux on discussions.apple.com.
1010
#
1111
# https://discussions.apple.com/thread/7520296?start=0&tstart=0
12+
13+
if [[ "$(uname -s)" != 'Darwin' ]]; then
14+
echo 'Sorry, this script only works on macOS'
15+
exit 1
16+
fi
17+
1218
now=$(date -u "+%Y-%m-%dT%TZ")
1319
defaults -currentHost write com.apple.notificationcenterui doNotDisturb -bool TRUE
1420
defaults -currentHost write com.apple.notificationcenterui doNotDisturbDate -date "$now"

bin/dump-entitlements

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ IFS=$'\n\t'
1414
# This makes bash consider newlines and tabs as separating words
1515
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
1616

17+
if [[ "$(uname -s)" != 'Darwin' ]]; then
18+
echo 'Sorry, this script only works on macOS'
19+
exit 1
20+
fi
1721

1822
function usage {
1923
echo

bin/enable-bouncing-dock-icons

+5
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66

77
set -o pipefail
88

9+
if [[ "$(uname -s)" != 'Darwin' ]]; then
10+
echo 'Sorry, this script only works on macOS'
11+
exit 1
12+
fi
13+
914
defaults write com.apple.dock no-bouncing -bool FALSE
1015
killall Dock

bin/enable-crash-reports

+5
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
#
55
# Copyright 2023, Joe Block <[email protected]>
66

7+
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
echo 'Sorry, this script only works on macOS'
9+
exit 1
10+
fi
11+
712
exec defaults write com.apple.CrashReporterDialogType crashreport

bin/enable-network-ds-store-files

+5
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
#
55
# Copyright 2020, Joe Block <[email protected]>
66

7+
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
echo 'Sorry, this script only works on macOS'
9+
exit 1
10+
fi
11+
712
exec defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool FALSE

bin/focusmode-disable

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#!/bin/bash
22

3+
if [[ "$(uname -s)" != 'Darwin' ]]; then
4+
echo 'Sorry, this script only works on macOS'
5+
exit 1
6+
fi
7+
38
# Disable Focus Mode (aka Single App Mode)
49
defaults write com.apple.dock single-app -bool false && killall Dock

bin/focusmode-enable

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#!/bin/bash
22

3+
if [[ "$(uname -s)" != 'Darwin' ]]; then
4+
echo 'Sorry, this script only works on macOS'
5+
exit 1
6+
fi
7+
38
# Enable Focus Mode (aka Single App Mode)
49
defaults write com.apple.dock single-app -bool true && killall Dock

bin/get-wallpaper-path

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/usr/bin/env bash
22

3-
osascript -e 'tell application "Finder"
3+
if [[ "$(uname -s)" != 'Darwin' ]]; then
4+
echo 'Sorry, this script only works on macOS'
5+
exit 1
6+
fi
7+
8+
exec osascript -e 'tell application "Finder"
49
set wall to desktop picture as alias
510
set wallpath to POSIX path of wall
611
end tell'

bin/get-wifi-password

+2
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ if [[ "$(uname -s)" = "Darwin" ]]; then
1313
security find-generic-password -ga "$1" 2>&1 | \
1414
grep 'password:' | \
1515
cut -c11-
16+
else
17+
echo "This only works on macOS"
1618
fi

bin/interface-style

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
22
#
3-
# Script skeleton
3+
# Read whether macOS is set to light or dark UI
44
#
5-
# Copyright 2022, Your Name <[email protected]>
5+
# Copyright 2022, Joe Block <[email protected]>
66

77
set -o pipefail
88
if [[ -n "$DEBUG" ]]; then
@@ -40,4 +40,9 @@ function interface-style() {
4040
fi
4141
}
4242

43+
if [[ "$(uname -s)" != 'Darwin' ]]; then
44+
echo 'Sorry, this script only works on macOS'
45+
exit 1
46+
fi
47+
4348
interface-style

bin/keychainctl

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
KEYCHAIN=${KEYCHAIN:-"secrets.keychain"}
66

7+
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
echo 'Sorry, this script only works on macOS'
9+
exit 1
10+
fi
11+
712
main () {
813
if [[ -z "$1" ]]; then
914
print_usage

bin/macos-major-version

+4
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
# every major rev or so. Add a helper to standardize detecting the rev
77

88
set -o pipefail
9+
if [[ "$(uname -s)" != 'Darwin' ]]; then
10+
echo 'Sorry, this script only works on macOS'
11+
exit 1
12+
fi
913

1014
sw_vers -productVersion | awk -F '.' '{print $1 "." $2}'

bin/markdown-open

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#
33
# https://github.com/rtomayko/dotfiles/blob/rtomayko/bin/markdown-open
44

5+
if [[ "$(uname -s)" != 'Darwin' ]]; then
6+
echo 'Sorry, this script only works on macOS'
7+
exit 1
8+
fi
9+
510
function debug() {
611
echo "$@" 1>&2
712
}

bin/mergepdfs

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
set -o pipefail
88

9+
if [[ "$(uname -s)" != 'Darwin' ]]; then
10+
echo 'Sorry, this script only works on macOS'
11+
exit 1
12+
fi
13+
914
usage() {
1015
echo "Usage:"
1116
# shellcheck disable=SC2086

bin/quicklook

+5
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ if [[ -n "$DEBUG" ]]; then
99
set -x
1010
fi
1111

12+
if [[ "$(uname -s)" != 'Darwin' ]]; then
13+
echo 'Sorry, this script only works on macOS'
14+
exit 1
15+
fi
16+
1217
# shellcheck disable=SC2048,SC2086
1318
(( $# > 0 )) && qlmanage -p $* &>/dev/null &

bin/smart-quote-disable

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
#
55
# Copyright 2021, Joe Block <[email protected]>
66

7-
exec defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false
7+
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
echo 'Sorry, this script only works on macOS'
9+
exit 1
10+
fi
811

12+
exec defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false

bin/smart-quote-enable

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@
44
#
55
# Copyright 2021, Joe Block <[email protected]>
66

7-
exec defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool true
7+
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
echo 'Sorry, this script only works on macOS'
9+
exit 1
10+
fi
811

12+
exec defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool true

bin/time-machine-log-viewer

+5
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ if [[ -n "$DEBUG" ]]; then
99
set -x
1010
fi
1111

12+
if [[ "$(uname -s)" != 'Darwin' ]]; then
13+
echo 'Sorry, this script only works on macOS'
14+
exit 1
15+
fi
16+
1217
# show --last 6h instead of stream will only dispay the last 6h, then quit.
1318
log stream --color always --predicate 'subsystem == "com.apple.TimeMachine"' --info | grep -v ' SmCp'

bin/time-machine-throttle

+5
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
#
55
# Copyright 2021, Joe Block <[email protected]>
66

7+
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
echo 'Sorry, this script only works on macOS'
9+
exit 1
10+
fi
11+
712
exec sudo sysctl debug.lowpri_throttle_enabled=1

bin/time-machine-unthrottle

+5
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
#
55
# Copyright 2021, Joe Block <[email protected]>
66

7+
if [[ "$(uname -s)" != 'Darwin' ]]; then
8+
echo 'Sorry, this script only works on macOS'
9+
exit 1
10+
fi
11+
712
exec sudo sysctl debug.lowpri_throttle_enabled=0

0 commit comments

Comments
 (0)