3

Prior to Catalina I used a script to trigger a sync to my iPhone and iPad - similar to:

tell application "iTunes"
    tell every source whose kind is iPod to update
end tell

Catalina removed iTunes and iOS devices are now synced using Finder.

What do I need to call in order to trigger a sync in Finder?

9
  • Did you try just changing iTunes to Music in your code? Also, devices were a part of Finder long before macOS Catalina. Oct 13 '19 at 9:54
  • @user3439894 - Yes - I did try using "Music". iPhones and iPads etc didn't appear in Finder prior to Catalina.
    – user44764
    Oct 13 '19 at 10:42
  • I meant the Devices category in Finder, i.e. Finder > Preferences > Sidebar > Devices not which devices show or not, sorry for any confusion. So when you used Music in the code, what happened, what was logged? Oct 13 '19 at 10:49
  • @user3439894 - Right - I thought you meant as a managed device (as in iTunes) . Sorry.
    – user44764
    Oct 13 '19 at 11:00
  • @user3439894 - I've added the output to the question
    – user44764
    Oct 13 '19 at 11:04
4

I expanded on dyindude's answer to make a single script that opens Finder, navigates to your device in the sidebar, waits for the sync button to appear, and clicks it. This assume's your device is named iPhone:

tell application "Finder" to open ("/" as POSIX file)

tell application "System Events" to tell outline 1 of scroll area 1 of splitter group 1 of window 1 of application process "Finder"
    set theElements to first UI element of every row whose name is "iPhone"
    repeat with e in theElements
        try
            if name of e is "iPhone" then
                tell e to perform action "AXOpen"
                exit repeat
            end if
        end try
    end repeat
end tell

tell application "System Events" to tell application process "Finder"
    repeat until button "Sync" of splitter group 1 of splitter group 1 of window "iPhone" exists
    end repeat

    click button "Sync" of splitter group 1 of splitter group 1 of window "iPhone"
end tell
1
  • This is great But .... it only works if the Finder has already got the Toolbar open, otherwise the :outline 1 of scroll area 1 of splitter group 1" gets a bad index. and I can't figure out how to tell the finder to view the toolbar - using Applescript always seems like guesswork rather than programming, and I just guessed wrong. Jul 4 at 1:40
1

This Applescript will click the "Sync" button in Finder on a window that already has the device open:

tell application "System Events" to tell application process "Finder"
   click button "Sync" of splitter group 1 of splitter group 1 of window "device name"
end tell

The following Applescript will navigate "window 1" of Finder to the device named "device name", where the "Sync" button is located.

tell application "System Events" to tell outline 1 of scroll area 1 of splitter group 1 of window 1 of application process "Finder"
set theElements to first UI element of every row whose name is "device name"
        repeat with e in theElements
            try
                if name of e is "device name" then
                tell e to perform action "AXOpen"
                exit repeat
                end if
            end try
        end repeat
end tell
0
0

I have found that I had to customise the above scripts quite a bit, to a) make it compatible with macOS Big Sur and b) because the finder does not reliably show my iPhone, even when they are in the same wifi network. What has helped is to restart the AMPLibraryAgent and the AMPDeviceDiscoveryDaemon.

Thus the AppleScript that now finally works reliably for me is this:

set iPhoneName to "My iPhone Name"

-- Open Finder window
tell application "Finder" to open ("/" as POSIX file)

on isPhoneVisible(iPhoneName)
    tell application "System Events" to tell outline 1 of scroll area 1 of splitter group 1 of window 1 of application process "Finder"
        set theElements to first UI element of every row whose name is iPhoneName
        repeat with e in theElements
            try
                if name of e is iPhoneName then
                    return true
                end if
            end try
        end repeat
    end tell
    return false
end isPhoneVisible

if not isPhoneVisible(iPhoneName) then
    -- Restart daemon that shows the iPhone in the sidebar so it is actually visible
    do shell script "pkill -9 AMPDevicesAgent AMPDeviceDiscoveryAgent"
end if


-- Select iPhone
-- needs retry until the iPhone becomes visible
tell application "System Events" to tell outline 1 of scroll area 1 of splitter group 1 of window 1 of application process "Finder"
    set hasFoundPhone to false
    repeat while not hasFoundPhone
        set theElements to first UI element of every row whose name is iPhoneName
        repeat with e in theElements
            try
                if name of e is iPhoneName then
                    tell e to perform action "AXOpen"
                    set hasFoundPhone to true
                    exit repeat
                end if
            end try
        end repeat
        delay 1
    end repeat
end tell

-- Start sync
tell application "System Events" to tell application process "Finder"
    repeat until button "Sync" of splitter group 1 of splitter group 1 of window iPhoneName exists
        delay 1
    end repeat
    
    click button "Sync" of splitter group 1 of splitter group 1 of window iPhoneName
end tell

You must log in to answer this question.