Last change
on this file since 631 was 630, checked in by Nicholas Riley, 14 years ago |
Update for iTunes 10 and to handle "Apply" button.
|
File size:
1.8 KB
|
Rev | Line | |
---|
[488] | 1 | #!/usr/bin/python
|
---|
| 2 | # -*- coding: utf-8 -*-
|
---|
| 3 |
|
---|
| 4 | from appscript import *
|
---|
[489] | 5 | from aem import AEEnum
|
---|
[491] | 6 | import sys
|
---|
[489] | 7 | import time
|
---|
[488] | 8 |
|
---|
[489] | 9 | def iTunes_main_pane():
|
---|
[630] | 10 | return app(u'System Events').application_processes[u'iTunes'].windows[u'iTunes'].scroll_areas[1]
|
---|
[488] | 11 |
|
---|
[489] | 12 | def wait_for_podcast_update(iTunes):
|
---|
| 13 | # show 'Podcasts'
|
---|
| 14 | iTunes.playlists[its.special_kind == AEEnum('kSpP')].reveal()
|
---|
| 15 | podcast_status = iTunes_main_pane().outlines[1].rows.static_texts[1].value
|
---|
[491] | 16 | while any(status in (u'downloading', u'queued for download')
|
---|
| 17 | for status in podcast_status.get()):
|
---|
[489] | 18 | time.sleep(0.5)
|
---|
[488] | 19 |
|
---|
[628] | 20 | def sync_iPod(iTunes):
|
---|
| 21 | try:
|
---|
| 22 | iTunes.update()
|
---|
| 23 | except CommandError:
|
---|
| 24 | print >> sys.stderr, 'No iPod detected. Waiting for iPod...'
|
---|
| 25 | while True:
|
---|
| 26 | time.sleep(0.5)
|
---|
| 27 | try:
|
---|
| 28 | iTunes.update()
|
---|
[629] | 29 | return
|
---|
[628] | 30 | except CommandError:
|
---|
| 31 | pass
|
---|
| 32 |
|
---|
[489] | 33 | # show iPod
|
---|
| 34 | iTunes.sources[its.kind == AEEnum('kPod')].sources[1].library_playlists[1].reveal()
|
---|
[628] | 35 |
|
---|
| 36 | # wait for update to complete
|
---|
[630] | 37 | def sync_enabled():
|
---|
[546] | 38 | try:
|
---|
[630] | 39 | iTunes_main_pane().buttons[u'Apply'].click()
|
---|
[546] | 40 | except CommandError:
|
---|
| 41 | pass
|
---|
[630] | 42 | try:
|
---|
| 43 | return iTunes_main_pane().buttons[u'Sync'].enabled.get()
|
---|
| 44 | except CommandError:
|
---|
| 45 | pass
|
---|
[489] | 46 |
|
---|
[630] | 47 | while not sync_enabled():
|
---|
| 48 | time.sleep(0.5)
|
---|
| 49 |
|
---|
[488] | 50 | if __name__ == '__main__':
|
---|
[489] | 51 | iTunes = app('iTunes')
|
---|
[609] | 52 | print >> sys.stderr, 'Starting podcast update...'
|
---|
| 53 | iTunes.updateAllPodcasts()
|
---|
[491] | 54 | print >> sys.stderr, 'Synchronizing iPod...'
|
---|
[628] | 55 | sync_iPod(iTunes)
|
---|
[491] | 56 | print >> sys.stderr, 'Updating podcasts...'
|
---|
[489] | 57 | iTunes.updateAllPodcasts()
|
---|
| 58 | wait_for_podcast_update(iTunes)
|
---|
[546] | 59 | print >> sys.stderr, 'Synchronizing iPod...'
|
---|
[628] | 60 | sync_iPod(iTunes)
|
---|
[574] | 61 | app(id='net.sabi.UpdatePodcasts').quit()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.