Skip to content

Commit a73f1a1

Browse files
committed
Disk Widgets
1 parent fc1de0e commit a73f1a1

5 files changed

+359
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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|[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{8\\}-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{4\\}-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{4\\}-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{4\\}-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{12\\}|#TAGGED#&|'" as string
28+
29+
--log thecommandstring
30+
set sedResult to do shell script thecommandstring
31+
32+
33+
set isgood to sedResult starts with "#TAGGED#"
34+
log "ITEM " & a & " IS " & sedResult
35+
log "===============TAG ITEM? " & isgood & "
36+
37+
"
38+
39+
if sedResult starts with "#TAGGED#" then
40+
set item a of listOfTaggedEDisks to "#./SKIPPED/.#"
41+
end if
42+
43+
end repeat
44+
45+
log "LIST AFTER " & listOfTaggedEDisks
46+
47+
48+
49+
50+
51+
52+
--remove gibberish disks
53+
set listOfFilteredEDisks to {}
54+
set thePosition to -1
55+
56+
repeat with a from 1 to length of listOfTaggedEDisks
57+
58+
set theCurrentListItem to item a of listOfTaggedEDisks
59+
60+
-- Process the current list item
61+
--log "current item: " & theCurrentListItem
62+
63+
if item a of listOfTaggedEDisks does not start with "#./SKIPPED/.#" then
64+
65+
set theItem to theCurrentListItem
66+
set theList to listOfFilteredEDisks
67+
68+
set theListCount to length of theList
69+
70+
if (thePosition * -1) is theListCount + 1 then
71+
set beginning of theList to theItem
72+
end if
73+
74+
set thePosition to (thePosition - 1)
75+
else
76+
--do nothing
77+
end if
78+
79+
end repeat
80+
81+
--set theList to reverse of theList
82+
log "FINAL LIST: " & theList
83+
84+
85+
--if first item of listOfFilteredEDisks does not start with "#./SKIPPED/.#" then
86+
eject item showdisknumber of theList
87+
88+
end tell
89+
on error
90+
return ""
91+
end try
92+
93+
(*
94+
set listOfEDisks to (get name of every disk whose ejectable is true)
95+
activate
96+
reveal first item of listOfEDisks
97+
*)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
regex
3+
regexr.com/6f0mp
4+
5+
([ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]{8}-([ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]{4}-){3}[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]{12})+
6+
7+
E6D0F693-82A6-5041-928B-04C89D2B5CCC
8+
F6AE7C61-BAD4-5123-A3E3-251EF23E447E
9+
8B4B0256-3C73-59CE-B218-03E2EBA0AD01
10+
11+
12+
sed
13+
https://www.grymoire.com/Unix/Sed.html#uh-62k
14+
15+
16+
17+
Regex in Applescript
18+
https://stackoverflow.com/questions/997828/is-there-something-akin-to-regex-in-applescript-and-if-not-whats-the-alternat
19+
20+
21+
22+
Remove item from a list
23+
https://stackoverflow.com/questions/68963070/remove-item-of-list-in-applescript
24+
25+
26+
List Operations
27+
https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ManipulateListsofItems.html#//apple_ref/doc/uid/TP40016239-CH48-SW1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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|[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{8\\}-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{4\\}-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{4\\}-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{4\\}-[ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890]\\{12\\}|#TAGGED#&|'" as string
28+
29+
--log thecommandstring
30+
set sedResult to do shell script thecommandstring
31+
32+
33+
set isgood to sedResult starts with "#TAGGED#"
34+
log "ITEM " & a & " IS " & sedResult
35+
log "===============TAG ITEM? " & isgood & "
36+
37+
"
38+
39+
if sedResult starts with "#TAGGED#" then
40+
set item a of listOfTaggedEDisks to "#./SKIPPED/.#"
41+
end if
42+
43+
end repeat
44+
45+
log "LIST AFTER " & listOfTaggedEDisks
46+
47+
48+
49+
50+
51+
52+
--remove gibberish disks
53+
set listOfFilteredEDisks to {}
54+
set thePosition to -1
55+
56+
repeat with a from 1 to length of listOfTaggedEDisks
57+
58+
set theCurrentListItem to item a of listOfTaggedEDisks
59+
60+
-- Process the current list item
61+
--log "current item: " & theCurrentListItem
62+
63+
if item a of listOfTaggedEDisks does not start with "#./SKIPPED/.#" then
64+
65+
set theItem to theCurrentListItem
66+
set theList to listOfFilteredEDisks
67+
68+
set theListCount to length of theList
69+
70+
if (thePosition * -1) is theListCount + 1 then
71+
set beginning of theList to theItem
72+
end if
73+
74+
set thePosition to (thePosition - 1)
75+
else
76+
--do nothing
77+
end if
78+
79+
end repeat
80+
81+
--set theList to reverse of theList
82+
log "FINAL LIST: " & theList
83+
84+
85+
--if first item of listOfFilteredEDisks does not start with "#./SKIPPED/.#" then
86+
activate
87+
reveal item showdisknumber of theList
88+
89+
end tell
90+
on error
91+
return ""
92+
end try
93+
94+
(*
95+
set listOfEDisks to (get name of every disk whose ejectable is true)
96+
activate
97+
reveal first item of listOfEDisks
98+
*)

macOS.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# General
2+
.DS_Store
3+
.AppleDouble
4+
.LSOverride
5+
6+
# Icon must end with two \r
7+
Icon
8+
9+
# Thumbnails
10+
._*
11+
12+
# Files that might appear in the root of a volume
13+
.DocumentRevisions-V100
14+
.fseventsd
15+
.Spotlight-V100
16+
.TemporaryItems
17+
.Trashes
18+
.VolumeIcon.icns
19+
.com.apple.timemachine.donotpresent
20+
21+
# Directories potentially created on remote AFP share
22+
.AppleDB
23+
.AppleDesktop
24+
Network Trash Folder
25+
Temporary Items
26+
.apdisk

0 commit comments

Comments
 (0)