-
-
Save TakesTheBiscuit/a2e3d36c1d20731821fdb41b3831406e to your computer and use it in GitHub Desktop.
Open and close CD/DVD Tray in python with Windows fix specific drive letter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from platform import system as platform_name | |
from os import system | |
import ctypes | |
platforms_dictionary = { | |
"Windows": { # | |
"open" : 'ctypes.windll.WINMM.mciSendStringW(u"open L: type CDAudio alias L_drive", None, 0, None); ctypes.windll.WINMM.mciSendStringW(u"set L_drive door open", None, 0, None)', | |
"close": 'ctypes.windll.WINMM.mciSendStringW(u"open L: type CDAudio alias L_drive", None, 0, None); ctypes.windll.WINMM.mciSendStringW(u"set L_drive door closed", None, 0, None)' | |
}, | |
"Darwin": { | |
"open" : 'system("drutil tray open")', | |
"close": 'system("drutil tray closed")' | |
}, | |
"Linux": { | |
"open" : 'system("eject cdrom")', | |
"close": 'system("eject -t cdrom")' | |
}, | |
"NetBSD": { | |
"open" : 'system("eject cd")', | |
"close": 'system("eject -t cd")' | |
}, | |
"FreeBSD": { | |
"open" : 'system("sudo cdcontrol eject")', | |
"close": 'system("sudo cdcontrol close")' | |
} | |
} | |
print(platform_name()) | |
if platform_name() in platforms_dictionary: | |
print('Opening..') | |
exec(platforms_dictionary[platform_name()]["open"]) | |
print('Closing..') | |
exec(platforms_dictionary[platform_name()]["close"]) | |
else: | |
print("Sorry, no OS found") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment