Got a weird on here and I sincerely hope I’m missing something really basic. I need to write a script to sync an AppleTV. The script below successfully sends the click to the menu item, but the click is not processed until I bring itunes to the front and (with the mouse) click on the menu bar. Then it starts syncing. Is there some sort of flush events call I need to make? (I’m on leopard 10.5.1 w. itunes 7.5) Telling iTunes to activate (see commented out lines) makes no difference.
--tell application "iTunes"
-- activate
tell application "System Events"
tell process "iTunes"
delay 1
tell menu item "Sync iPod" of menu 1 of menu bar item "File" of menu bar 1 to click
--click menu bar 1
delay 1
end tell
-- end tell
end tell
Two other notes. For this to work, you have to enable assistive devices in the universal access control panel. Also, trying to access the menu item by number yields the same result. i.e.
tell menu item 23 of menu 1 of menu bar item "File" of menu bar 1 to click
For the curious, I’ve put a folder action on the photobooth folder to add new photos to iphoto. AppleTV is syncing with a smart iphoto folder containing those images. While the slide show on the AppleTV is running, you can sync the AppleTV with itunes and the slide show automatically updates with the new photos. Upshot: Party guests can use photobooth, and the pictures show up on the appletv slideshow. Works beautifully except for the weird itunes menu delay.
Thanks for the quick response, and please understand I would love to.
Your script gives a ‘iTunes got an error: source 1 whose kind = iPod doesn’t understand the update message.’
Tried that first. Apparently the Apple TV’s source is showing up as a ‘radio tuner’ which won’t update. The following script (apologies to Jonathan Strine for mutilating it) give a ‘Your ipod is not set up to sync’
That’s what started me down the menu item path.
(*
"Update iPod" for iTunes
written by Jonathan Strine
strinej@netpanel.com
Get more free AppleScripts and info on writing your own
at Doug's AppleScripts for iTunes
http://www.malcolmadams.com/itunes/
*)
on isProcessRunning(processName)
tell application "System Events"
return ((application processes whose (name is equal to processName)) count)
end tell
end isProcessRunning
if isProcessRunning("iTunes") > 0 then
tell application "iTunes"
repeat with n from 1 to the count of sources
-- if the kind of source n is iPod then
if the kind of source n is not library then
--return kind of source 2
try
update n
on error
display dialog "Your iPod is not set up to sync." & return & return & "To use this script, set your iPod Preferences to \"Automatically update...\"" buttons {"Cancel"} default button 1 with icon 2 giving up after 15
end try
end if
end repeat
return sources
end tell
end if
ps: this behavior happens with other menu items as well. if you change it to menu item 9, no response until you click on the menu bar