AppleScript error -1728 while accessing menu I am getting following error for the script below. Please help

error "System Events got an error: Can’t get menu bar item \"File\" of process \"iTunes\"." number -1728 from menu bar item "File" of process "iTunes"

Script I wrote

tell application "iTunes"
 activate
 tell application "System Events"
    tell process "iTunes"
        click menu item "Sync \"iPhone\"" of menu item "Devices" of menu bar item "File"
    end tell
 end tell
end tell
This works for me to sync my iPhone in iTunes:

tell application "iTunes"
    activate
    delay 1
    tell application "System Events"
        click menu item 1 of menu 1 of menu item "Devices" of menu 1 of menu bar item "File" of menu bar 1 of application process "iTunes"
    end tell
end tell



click menu item 1 can also be e.g., click menu item "Sync “Iam’s iPhone”"
Note that the value of the delay command(s) may need to be adjusted for your system, and or additional delay commands may or may not be needed. Adjust values of and or add/remove the delay commands as appropriate.




Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.