Using AppleScript to sync iPhone in Catalina

Solution 1:

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

Solution 2:

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