-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy patheject-all
executable file
·60 lines (48 loc) · 1.23 KB
/
eject-all
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
#!/usr/bin/env bash
function eject_all() (
source "$DOROTHY/sources/bash.bash"
# =====================================
# Arguments
function help {
cat <<-EOF >/dev/stderr
ABOUT:
Eject all the ejectable drives attached to the system.
USAGE:
eject-all
EOF
if [[ $# -ne 0 ]]; then
echo-error "$@"
fi
return 22 # EINVAL 22 Invalid argument
}
# process
local item
while [[ $# -ne 0 ]]; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*) help "An unrecognised argument was provided: $item" ;;
esac
done
# =====================================
# Action
echo-style --h1='eject-all'
echo-style --h2='before'
fs-structure -- /Volumes
echo-style --g2='before'
eval-helper --quiet \
--pending="$(echo-style --bold='Ejecting...')" \
--success="$(echo-style --success='Ejected.')" \
--failure="$(echo-style --error='Failed to eject.')" \
-- osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'
echo-style --h2='after'
fs-structure -- /Volumes
echo-style --g2='after'
echo-style --h1='eject-all'
)
# fire if invoked standalone
if [[ $0 == "${BASH_SOURCE[0]}" ]]; then
eject_all "$@"
fi