Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A very quick introduction to Java...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A very quick introduction to Java...
Authored by: kesmit on May 03, '03 10:41:11PM
Here is the same thing, but in Python. You'll have to download the Objective C->Python bridge from http://sourceforge.net/ project/showfiles.php?group_id=14534. Just copy the following code to a file called "iTunesControl" and do "chmod +x iTunesControl". Then you can type "iTunesControl play" (or any other command).
#!/usr/bin/env python

import os, sys
from objc import *
from Foundation import *
from AppKit import *

class iTunesControl(object):

    def play(self):
        self.doScript('tell application "iTunes" to play')

    def pause(self):
        self.doScript('tell application "iTunes" to pause')

    def next(self):
        self.doScript('tell application "iTunes" to next track')

    def previous(self):
        self.doScript('tell application "iTunes" to previous track')

    def doScript(self, script):
        myscript = NSAppleScript.alloc().initWithSource_(script) 
        myscript.executeAndReturnError_({})

try:
    command = getattr(iTunesControl(), sys.argv[1])
    command()
except AttributeError:
    print 'Command %s does not exist' % sys.argv[1]
except IndexError:
    print 'usage: %s (play|pause|next|previous)' % 
os.path.basename(sys.argv[0])


[ Reply to This | # ]