#1
  1. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15

    controlling itunes on a mac


    because of this post i've had no problems at all controlling itunes in windows with python.

    now i want to do this on my mac...anyone have any good ideas?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Assuming you don't wana use Applescript (not the nicest language but it does give you a change every now and again) you can use Hamish Sandersons "appscript"; a very Pythonic way to control scriptable Mac Applications .

    I'm a huge fan of this one:

    http://freespace.virgin.net/hamish.sanderson/appscript.html

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    Originally Posted by netytan
    Assuming you don't wana use Applescript (not the nicest language but it does give you a change every now and again) you can use Hamish Sandersons "appscript"; a very Pythonic way to control scriptable Mac Applications .

    I'm a huge fan of this one:

    http://freespace.virgin.net/hamish.sanderson/appscript.html

    Mark.
    that's perfect! thanks

    i am having a heck of a time finding example scripts on actually just playing a playlist....instead of just doing itunes admin stuff. you got any???

    thanks again

    <edit>

    i wrote what i wanted in applescript:

    Code:
    tell application "iTunes"
    	set myPlaylist to playlist "f"
    	play myPlaylist
    	set visuals enabled to true
    end tell
    ...so how would i do that in the python with that?

    </edit>
    Last edited by jacktasia; March 28th, 2005 at 09:29 PM.
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Hey Jack,

    there's probably little point in pursuing this since you've already done it in Applescript but this is the rough equivalent of the script you posted using Python:

    Code:
    #!/usr/bin/env pythonw
    
    from appscript import *
    
    iTunes = app('iTunes')
    iTunes.play(iTunes.sources['Library'])
    iTunes.visuals_enabled.set(True)
    Note: remember to run this with pythonw not python. Also, make sure you're using the version of Python appscript was installed for if you have more than one version on your system.


    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    the reason why i wrote this was i wanted to be able to control my itunes on my desktop (good speakers) from my laptop on my bed over ssh.

    Code:
    from appscript import *
    
    
    
    # list of acceptable commands
    okay_cmds = ['play','pause','visualon','visualoff']
    #list of all playlists
    okay_play = app('iTunes').sources[1].user_playlists.name.get()
    #my special project
    
    iTunes = app('iTunes')
    
    i =''
    
    while i != 'bye':
    	f = False
    	print "iTunes should do: ",
    	i = str(raw_input())
    	
    	if i == 'bye':
    		f = True
    	
    	if i in okay_play:
    		iTunes.play(iTunes.sources[1].user_playlists[i])
    		f = True
    	if i in okay_cmds:
    		if i == 'play':
    			iTunes.play()
    		elif i=='pause':
    			iTunes.pause()
    		elif i == 'visualon':
    			iTunes.visuals_enabled.set(True)
    		elif i=='visualoff':
    			iTunes.visuals_enabled.set(False)
    		f = True
    	
    	if f ==False:
    		print "**That's not something I can do!"
    
    	
    print
    print "thanks!"
    if anyone ever uses this remember to run it with pythonw
    Last edited by jacktasia; March 29th, 2005 at 11:14 PM.

IMN logo majestic logo threadwatch logo seochat tools logo