Automatically Refreshing Photos in iTunes for Apple TV
Ask iLounge offers readers the opportunity to get answers to their iPod-, iPhone-, iPad-, iTunes-, or Apple TV-related questions from a member of the iLounge editorial team. We'll answer several questions here each week, and of course, you can always get help with more immediate concerns from the iLounge Discussion Forums. Submit your questions for consideration using our Ask iLounge Submit Form. We reserve the right to edit questions for grammar, spelling, and length.
Q: I found your article last week on Refreshing Photo Albums on the Apple TV and I’m in a similar situation. I’m a Mac user, but I prefer to use folders for my Apple TV as I want to be able to quickly add new pictures without having to go through iPhoto. I also leave my iMac and iTunes on all of the time, which I gather from your article is why I don’t see new photos showing up. Is there some way to automatically refresh my photos through AppleScript or something that would be easier than going in and messing with the sharing settings whenever I add something to my photo folders? I’ve seen some tips on setting up iTunes to restart automatically on a schedule, but I don’t want to do that because I’m often downloading new stuff or using the Apple TV to watch or listen to something from iTunes.
A: This actually is possible via AppleScript; it’s a bit kludgy since it uses a feature known as “GUI Scripting” which basically just selects the normal iTunes options on your behalf, but it gets the job done.
Unfortunately, none of the photo sharing features in iTunes are exposed directly to AppleScript, so we’re forced to resort to manipulating iTunes controls directly. To allow AppleScript to do this on your behalf, it is first necessary to go into your OS X System Preferences application and select the Enable access for assistive devices option under your Universal Access settings.
The option allows AppleScript to directly access user interface elements in applications on your Mac. Once you’ve done this, an AppleScript such as the following can be used to refresh your photo folders in iTunes simply by going through the steps of opening the Choose Photos to Share dialog, changing some options and then closing that window afterwards.
tell application "System Events" if my appIsRunning("iTunes") then tell process "iTunes" # Open the Photo Sharing settings from the "Advanced" menu click menu item "Choose Photos to Share…" of menu ¬ "Advanced" of menu bar item "Advanced" of menu bar 1 # Toggle the status of the "Include videos" checkbox to force a change click checkbox "Include videos" of scroll area 1 of window "Photo Sharing Preferences" click button "Apply" of window "Photo Sharing Preferences" # Toggle the status of the "Include videos" checkbox again to return it to its original setting click checkbox "Include videos" of scroll area 1 of window "Photo Sharing Preferences" click button "Apply" of window "Photo Sharing Preferences" # Close the Photo Sharing settings window click (first button of window "Photo Sharing Preferences" whose subrole is "AXCloseButton") end tell end if end tell on appIsRunning(appname) tell application "System Events" to (name of processes) contains appname end appIsRunning
The in-line comments in the script above describe what it does. To summarize, we’re confirming that iTunes is running, and if so simply toggling the Include videos option to force iTunes to re-read the photo collection. The Include videos option is toggled a second time to return it to its original setting before closing the window. Note that if you don’t normally include videos in your photo folders anyway, you can remove this second section as it doesn’t matter whether the Include videos option is set or not.
If iTunes is not running in this case, the script does nothing, since starting up iTunes would refresh the photo folders anyway, effectively rendering the remainder of the script redundant.
To use the script, you can simply choose to run it manually, saving it in AppleScript editor as an “Application” that you can then put somewhere convenient—such as on your Desktop or in your Dock—and simply run by clicking on it.
Alternatively, you could set the script up to run either on a scheduled basis or as a Folder Action that is triggered whenever you make a change to one of your photo folders.
Setting your script up to run on a schedule is most easily and transparently done with the third-party utility Lingon ($3), however it is also possible to schedule it as a recurring iCal event with an alert type of “Run Script”.
Another way to approach this is to setup the script to run as a Folder Action against whatever folders you normally use for photos. This first requires a very slight modification to the above AppleScript to add the appropriate Folder Action handlers, as follows:
At the top of the script, add…
on adding folder items to this_folder after receiving added_items tell application "System Events" if my appIsRunning("iTunes") then tell process "iTunes" … …
…and at the bottom, insert:
… … end tell end adding folder items to on appIsRunning(appname) tell application "System Events" to (name of processes) contains appname end appIsRunning
You then need to save the script in your ~/Library/Scripts/Folder Action Scripts folder and you should then be able to associate the script with the appropriate folder by right-clicking on the folder in Finder and choosing Services, Folder Actions Setup…
Note that Folder Actions do not include sub-folders by default, so you will need to associate the script with each folder where you plan to add photos on a regular basis. Further, the script modifications above will only be initiated when adding new items to your Photos folder; if you want to have the script also run when removing items, you will need to add another copy of the main code block with the handler on removing folder items from this_folder after losing removed_items. This is left as an exercise for the reader, or you can simply download a complete version of the script ready to be used as a Folder Action.
In regard to automating the script, it’s important to note that since it uses GUI scripting and is therefore interacting directly with the active user interface, it may be inconvenient to have it run at times when you may otherwise be working. It is recommended to either run it on a schedule based on when you’re unlikely to be using the computer, or, if running it as a Folder Action, be sure to wait two or three seconds after adding or removing files for the iTunes window to pop-up and disappear before continuing whatever else you’re doing.
It’s also important to note that this script was designed for iTunes 10.6.3 specifically. It is very likely to break or require modifications in future versions of iTunes, particularly if Apple decides to reorganize the photo sharing procedures. Of course, ideally we hope that Apple fixes the photo folder refresh issue in a future version of iTunes, thereby making such workarounds completely unnecessary.
- Will removing a credit card from Safari also remove it from Apple Pay?
- Can I mute Handoff calls coming into my Mac from my iPhone?
- How do I keep my iPhone calls from ringing on my Mac?
- Why doesn’t Traffic show up on my Today Notifications Screen?
- Why doesn’t my iPhone reconnect to Wi-Fi after I turn it on?
- Why can’t I see the iPad-style landscape view on my iPhone 6 Plus?
- ConnectSense Smart Outlet adds power monitoring, reduces price
- Automatic releases new Automatic Lite version of car monitoring accessory
- Apple releases fourth tvOS 10.0.1 beta
- iOS dev finds unimplemented one-handed keyboard in iOS code
- Apple sends out press invites for ‘Hello Again’ Oct. 27 Mac event
- Apple releases fifth beta of iOS 10.1 to developers
- Apple partners with builders to include HomeKit-enabled devices in new homes
- Report about Apple Pay in Japan hints at Oct. 25 release for iOS 10.1
- Apple Pay adds 20+ new U.S. banks and credit unions, MBNA Canada coming ‘mid-2017’
- Misfit launches Phase smartwatch
- Incase Icon, Pop, and Textured Snap for iPhone 7/7 Plus
- Philips Hue Motion Sensor
- Bowers & Wilkins P9 Signature Headphones
- Tech Armor FlexProtect and Shock Flex for iPhone 7/7 Plus
- SwitchEasy Flash and Fleur for iPhone 7/7 Plus
- Blue Microphones Raspberry Mobile Microphone
- Incipio Haven for iPhone 7 and Reprieve Sport for iPhone 7 Plus
- Mophie Hold Force Magnetic Case System for iPhone 7
- Speck Presidio and Tech21 Evo Tactical for iPhone 7
- Belkin Lightning Audio + Charge Rockstar
- Instant Expert: Secrets & Features of watchOS 3
- Instant Expert: Secrets & Features of tvOS 10
- Instant Expert: Secrets & Features of iOS 10
- Inside the betas: iOS 10 Photos gets Advanced Computer Vision
- Inside the betas: iOS 10 Music app delivers ‘clarity and simplicity’
- Inside the betas: iOS 10 Maps gets a major redesign
- Inside the betas: iOS 10 shakes up the user experience
- Inside the betas: watchOS 3 promises a real speed boost
- Inside the betas: A sneak peek at what’s new in tvOS 10
- Filling the Gap: A look at third-party HomeKit apps