|
|
A very quick introduction to Java...
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])
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.09 seconds |
|