-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiskutil.py
More file actions
24 lines (20 loc) · 1.14 KB
/
Diskutil.py
File metadata and controls
24 lines (20 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import subprocess
# sample output of diskutil
# ***DiskAppeared ('disk5', DAVolumePath = '<null>', DAVolumeKind = 'msdos', DAVolumeName = 'Kindle') Time=20221231-16:38:26.6321
# ***DiskMountApproval ('disk5', DAVolumePath = '<null>', DAVolumeKind = 'msdos', DAVolumeName = 'Kindle') Comment=Approving Time=20221231-16:38:26.6327
# ***DiskDescriptionChanged ('disk5', DAVolumePath = 'file:///Volumes/Kindle/') Time=20221231-16:38:26.9476
# ***DAIdle (no DADiskRef) Time=20221231-16:38:26.9477
class Diskutil:
def waitForKindleConnection(self):
# execute diskutil activity process and read each output line
process = subprocess.Popen(['diskutil', 'activity'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# while reading lines from process
while True:
line = process.stdout.readline()
if not line:
break
line = line.decode('utf-8')
# if line starts with '***DiskAppeared', parse line
if line.startswith('***DiskMountApproval') and 'Kindle' in line:
print('Kindle connected')
yield True