1
+ set showdisknumber to 1
2
+
3
+ try
4
+ tell application " Finder"
5
+
6
+ -- get all disks
7
+ set num_ejectable to count of (every disk whose ejectable is true )
8
+ if num_ejectable is greater than 0 then
9
+ set listOfEDisks to (get name of every disk whose ejectable is true and name does not contain " Macintosh HD" and startup is false )
10
+ end if
11
+
12
+
13
+
14
+
15
+ -- tag gibberish disks
16
+ set listOfTaggedEDisks to listOfEDisks
17
+
18
+ log " LIST BEFORE " & listOfTaggedEDisks
19
+
20
+ repeat with a from 1 to length of listOfTaggedEDisks
21
+
22
+ set theCurrentListItem to item a of listOfTaggedEDisks
23
+
24
+ -- Process the current list item
25
+ -- log "current item: " & theCurrentListItem
26
+
27
+ -- set thecommandstring to "echo \"" & theCurrentListItem & "\"|sed -e 's|CleanMyMac X 4.10.1|#TAGGED#&|'" as string
28
+
29
+ set thecommandstring to " echo \" " & theCurrentListItem & " \" |sed -e 's|[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\ {8\\ }-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\ {4\\ }-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\ {4\\ }-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\ {4\\ }-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\ {12\\ }|#TAGGED#&|'" as string
30
+
31
+ -- log thecommandstring
32
+ set sedResult to do shell script thecommandstring
33
+
34
+
35
+ set isgood to sedResult starts with " #TAGGED#"
36
+ log " ITEM " & a & " IS " & sedResult
37
+ log " ===============TAG ITEM? " & isgood & "
38
+
39
+ "
40
+
41
+ -- log sedResult & " is item " & a & " in the list."
42
+
43
+
44
+ if sedResult starts with " #TAGGED#" then
45
+ set item a of listOfTaggedEDisks to " #./SKIPPED/.#"
46
+ end if
47
+
48
+ end repeat
49
+
50
+ log " LIST AFTER " & listOfTaggedEDisks
51
+
52
+
53
+
54
+
55
+
56
+
57
+ -- remove gibberish disks
58
+ set listOfFilteredEDisks to {}
59
+ set thePosition to -1
60
+
61
+ repeat with a from 1 to length of listOfTaggedEDisks
62
+
63
+ set theCurrentListItem to item a of listOfTaggedEDisks
64
+
65
+ -- Process the current list item
66
+ -- log "current item: " & theCurrentListItem
67
+
68
+ if item a of listOfTaggedEDisks does not start with " #./SKIPPED/.#" then
69
+
70
+ set theItem to theCurrentListItem
71
+ set theList to listOfFilteredEDisks
72
+
73
+ set theListCount to length of theList
74
+
75
+ if (thePosition * -1 ) is theListCount + 1 then
76
+ set beginning of theList to theItem
77
+ end if
78
+
79
+ set thePosition to (thePosition - 1 )
80
+ else
81
+ -- do nothing
82
+ end if
83
+
84
+ end repeat
85
+
86
+ -- set theList to reverse of theList
87
+ log " FINAL LIST: " & theList
88
+
89
+
90
+ -- if first item of listOfFilteredEDisks does not start with "#./SKIPPED/.#" then
91
+ if the length of theList is greater than or equal to showdisknumber then
92
+ set thisDisk to item showdisknumber of theList
93
+
94
+ set thecapacity to capacity of disk thisDisk
95
+ set thefreespace to free space of disk thisDisk
96
+
97
+ set roundedcap to round (thecapacity / 1.0E+8 / 10 )
98
+ set roundedfree to round (thefreespace / 1.0E+7 )
99
+ set roundedfree to roundedfree * 0.01
100
+
101
+ return "" & thisDisk & "
102
+ " & roundedfree & " GB free of " & roundedcap & " GB"
103
+ else
104
+ log " not enough disks"
105
+ return ""
106
+ end if
107
+
108
+ end tell
109
+ on error
110
+ return ""
111
+ end try
0 commit comments