Created
June 1, 2014 13:08
-
-
Save Na0ki/b97cb1e97aabc2d525cc to your computer and use it in GitHub Desktop.
multi platform eject command using python
This file contains 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
# coding: UTF-8 | |
import platform | |
import os | |
import ctypes | |
# windows | |
if platform.system() == 'Windows': | |
# need 'u' before "", if you are using UTF-8. if not you don't need to put it. | |
ctypes.windll.WINMM.mciSendStringW(u"set cdaudio door open", None, 0, None) | |
#ctypes.windll.WINMM.mciSendStringW(u"set cdaudio door closed", None, 0, None) | |
print "Windows worked\n" | |
# OSX | |
elif platform.system() == 'Darwin': | |
os.system("drutil tray open") | |
#os.system("drutil tray closed") | |
print "Darwin worked\n" | |
# Linux | |
elif platform.system() == 'Linux': | |
os.system("eject cdrom") | |
#os.system("eject -t cdrom") | |
print "Linux worked\n" | |
# NetBSD | |
# thank you to the man who adviced me how to eject on NetBSD | |
elif platform.system() == 'NetBSD': | |
#you must be su | |
os.system("eject cd") | |
print "NetBSD worked\n" | |
####################################################### | |
# Operation under this comment has not been confirmed # | |
####################################################### | |
# FreeBSD | |
elif platform.system() == 'FreeBSD': | |
#you can use cdcontrol without typing su password. but do it on your own responsibility. | |
#visudo /usr/local/etc/sudoers | |
#username ALL=(ALL) NOPASSWD: /usr/sbin/cdcontrol | |
os.system("sudo cdcontrol eject") | |
#os.system("sudo cdcontrol close") | |
print "FreeBSD worked\n" | |
else: | |
print "OS Unsupported\n" | |
# if needed | |
# print "UIIIIIIIN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi..from your code I did another version: https://gist.github.com/rvzzz/d7bef0c7ff49bf3734d374ce056a8089
the windows stuff was giving a lint problem but i left it as it was...and actually ignore it during the edit...
It wasn't recognizing the namespace or whatever. But if it worked for you I it will work still