def skip(): """Tell iTunes to skip a song""" if not settings.platformCompatible(): return False (output, error) = subprocess.Popen(["osascript", "-e", SKIP], stdout=subprocess.PIPE).communicate()
def resume(): """Tell iTunes to resume""" if not settings.platformCompatible(): return False (output, error) = subprocess.Popen(["osascript", "-e", RESUME], stdout=subprocess.PIPE).communicate()
def saveDirectory(alias): """save a directory to a certain alias/nickname""" if not settings.platformCompatible(): return False dataFile = open(settings.getDataFile(), "wb") currentDirectory = os.path.abspath(".") directory = {alias : currentDirectory} pickle.dump(directory, dataFile) speech.success(alias + " will now link to " + currentDirectory + ".") speech.success("Tip: use 'hallie go to " + alias + "' to change to this directory.")
def saveDirectory(alias): """save a directory to a certain alias/nickname""" if not settings.platformCompatible(): return False dataFile = open(settings.getDataFile(), "wb") currentDirectory = os.path.abspath(".") directory = {alias: currentDirectory} pickle.dump(directory, dataFile) speech.success(alias + " will now link to " + currentDirectory + ".") speech.success("Tip: use 'hallie go to " + alias + "' to change to this directory.")
def play(song, artist=None, album=None): """Tells iTunes to play a given song/artist/album - MACOSX ONLY""" if not settings.platformCompatible(): return False if song and not artist and not album: (output, error) = subprocess.Popen( ["osascript", "-e", DEFAULT_ITUNES_PLAY % (song, song, song)], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.") elif song and artist and not album: (output, error) = subprocess.Popen([ "osascript", "-e", ITUNES_SONG_AND_ARTIST % (song, artist, song, artist) ], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.") elif album and artist and not song: (output, error) = subprocess.Popen( ["osascript", "-e", ITUNES_ALBUM_AND_ARTIST % (artist, album)], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.") elif album and not artist and not song: (output, error) = subprocess.Popen(["osascript", "-e", ITUNES_ALBUM % (album)], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.") elif artist and not album and not song: (output, error) = subprocess.Popen( ["osascript", "-e", ITUNES_ARTIST % (artist)], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.")
def goToDirectory(alias): """go to a saved directory""" if not settings.platformCompatible(): return False data = pickle.load(open(settings.getDataFile(), "rb")) try: data[alias] except KeyError: speech.fail("Sorry, it doesn't look like you have saved " + alias + " yet.") speech.fail("Go to the directory you'd like to save and type 'hallie save as " + alias + "\'") return try: (output, error) = subprocess.Popen(["osascript", "-e", CHANGE_DIR % (data[alias])], stdout=subprocess.PIPE).communicate() except: speech.fail("Something seems to have gone wrong. Please report this error to [email protected].") return speech.success("Successfully navigating to " + data[alias])
def play(song, artist=None, album=None): """Tells iTunes to play a given song/artist/album - MACOSX ONLY""" if not settings.platformCompatible(): return False if song and not artist and not album: (output, error) = subprocess.Popen(["osascript", "-e", DEFAULT_ITUNES_PLAY % (song, song, song)], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.") elif song and artist and not album: (output, error) = subprocess.Popen(["osascript", "-e", ITUNES_SONG_AND_ARTIST % (song, artist, song, artist)], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.") elif album and artist and not song: (output, error) = subprocess.Popen(["osascript", "-e", ITUNES_ALBUM_AND_ARTIST % (artist, album)], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.") elif album and not artist and not song: (output, error) = subprocess.Popen(["osascript", "-e", ITUNES_ALBUM % (album)], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.") elif artist and not album and not song: (output, error) = subprocess.Popen(["osascript", "-e", ITUNES_ARTIST % (artist)], stdout=subprocess.PIPE).communicate() if output: speech.speak("Playing " + output) else: speech.speak("Unable to find " + song + " in your library.")
def goToDirectory(alias): """go to a saved directory""" if not settings.platformCompatible(): return False data = pickle.load(open(settings.getDataFile(), "rb")) try: data[alias] except KeyError: speech.fail("Sorry, it doesn't look like you have saved " + alias + " yet.") speech.fail( "Go to the directory you'd like to save and type 'hallie save as " + alias + "\'") return try: (output, error) = subprocess.Popen( ["osascript", "-e", CHANGE_DIR % (data[alias])], stdout=subprocess.PIPE).communicate() except: speech.fail( "Something seems to have gone wrong. Please report this error to [email protected]." ) return speech.success("Successfully navigating to " + data[alias])