Created
March 20, 2016 11:55
-
-
Save alessaba/c0deb6714a9aff9f1da9 to your computer and use it in GitHub Desktop.
VolumeControls.py
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 | |
from objc_util import NSBundle, ObjCClass, on_main_thread | |
NSBundle.bundleWithPath_('/System/Library/Frameworks/MediaPlayer.framework').load() | |
MPVolumeView = ObjCClass('MPVolumeView') | |
volume_view = MPVolumeView.new().autorelease() | |
@on_main_thread | |
def set_system_volume(value): | |
volume_view.subviews()[0].value = value | |
@on_main_thread | |
def get_system_volume(): | |
return volume_view.subviews()[0].value() | |
def upAction(): | |
#Volume Up button has been pressed | |
print 'Up!' | |
def downAction(): | |
#Volume Down button has been pressed | |
print 'Down!' | |
default = get_system_volume() | |
def main(): | |
try: | |
while True: | |
if get_system_volume() > default: | |
upAction() | |
set_system_volume(default) | |
elif get_system_volume() < default: | |
downAction() | |
set_system_volume(default) | |
except KeyboardInterrupt: | |
pass | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment