-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnteringSafeSleepmode.sh
executable file
·71 lines (54 loc) · 1.34 KB
/
EnteringSafeSleepmode.sh
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
#!/bin/bash
read -p "Do you want to unmount and eject external drives and hibbernate? (y/n)" var1
var1=`echo $var1 | tr '[:upper:]' '[:lower:]'`
if [ $var1 = "y" ] || [ $var1 = "n" ] || [ $var1 = "j" ]
then
echo ""
else
echo "Wrong input .... please type (y)es or (n)o .... stopping the program"
sleep 3
exit 1
fi
if [ $var1 = "n" ]
then
echo "Stopping Process"
sleep 3
exit 0
fi
echo " Unmounting Disks ...."
countdrives=`diskutil list | grep -c "/disk"`
#usallay two paritions in use
if [ $countdrives -gt 3 ]
then
#Mac has /disk0 and /disk1 in use. Counting starts at Zero.... -1 corrects the factor for loop
let countdrives=countdrives-1
#Building realistic number for output (-1)
tounmount=$countdrives
let tounmount=tounmount-1
echo "$tounmount Volumes to unmount ..."
while [ $countdrives -gt 1 ]
do
diskutil unmountDisk /dev/disk$countdrives
let countdrives=countdrives-1
done
fi
#eject Drives -> Pretty much same procedure as above
edrives=`diskutil list | grep -c "/disk"`
if [ $edrives -gt 3 ]
then
#realistic numbers
let edrives=edrives-1
let toeject=edrives-1
echo "$toeject Volumes to eject ..."
while [ $edrives -gt 1 ]
do
diskutil eject /dev/disk$edrives
let edrives=edrives-1
done
fi
echo "Unmounting and ejecting of drives complete"
sleep 1
echo "Entering sleepmode.... "
sleep 2
pmset sleepnow
exit 0