-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmac
executable file
·117 lines (98 loc) · 2.81 KB
/
mac
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
#
# CLI to perform macOS common tasks.
usage() {
cat <<- EOF
Usage: mac [OPTIONS]
Easily perform macOS common tasks.
Available mac commands:
* Apps:
close-all-apps Close all opened apps except Finder, iTerm, and Dropbox
* System:
info Show macOS version information
lock Lock screen and launch screen saver
empty-trash Empty trash
update Install macOS software updates, Homebrew and installed formulas,
Vim and its plugins, Solarized repositories, and dotfiles submodules
* WI-FI:
check-internet Test network connectivity
ip Show local and public IP addresses
wifi-history List Previously Used Wi-Fi Networks
EOF
}
#-------------------------------------
# Apps
#-------------------------------------
close_all_apps() {
whitelist="grep\|iTerm\|Finder\|Dropbox"
ps aux |
grep /Applications |
grep -v $whitelist |
sed "s/\ *\ /\ /g" |
cut -d ' ' -f 2 |
xargs -I X kill -9 X
}
#-------------------------------------
# System
#-------------------------------------
empty_trash() {
rm -rf ~/.Trash/*
}
launch_screen_saver() {
open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app
}
#-------------------------------------
# WI-FI
#-------------------------------------
show_ip_address() {
# shellcheck disable=SC2155
local external_ip_addr="$(dig +short myip.opendns.com @resolver1.opendns.com)"
# shellcheck disable=SC2155
local local_ip_addr="$(ipconfig getifaddr en0)"
printf "Local IP Address: %s\n" "$local_ip_addr"
printf "External IP Address: %s\n" "$external_ip_addr"
}
show_wifi_history() {
defaults read /Library/Preferences/SystemConfiguration/com.apple.airport.preferences |
grep LastConnected -A 7 |
less
}
test_network_connectivity() {
ping -o google.com
}
#-------------------------------------
# Main
#-------------------------------------
main() {
case $1 in
help )
usage
exit
;;
#-------------------------------------
# Apps
#-------------------------------------
close-all-apps ) close_all_apps ;;
#-------------------------------------
# System
#-------------------------------------
empty-trash ) empty_trash ;;
info ) sw_vers ;;
lock ) launch_screen_saver ;;
update ) update-system ;;
#-------------------------------------
# WI-FI
#-------------------------------------
check-internet ) test_network_connectivity ;;
ip ) show_ip_address ;;
wifi-history ) show_wifi_history ;;
#-------------------------------------
# Unknown
#-------------------------------------
* )
echo "mac: '$1' is not a mac command. See 'mac help'."
exit 1
;;
esac
}
main "$@"