Help with an AppleScript - click a menu item which has a name which changes

Inbox has a 'get out of jail free' card - it's accessible by simple key command, by default
Cmd ⌘ 1

That means you can get away with

tell application "Mail" to activate
tell application "System Events" to keystroke "1" using command down

If you get a permissions error, then it seems the way to add perms is to put

do shell script "osascript -e 'tell application \"Mail\" to activate'"

at the head of the script one time & run it. You should then get the opportunity to add to the Automation perms in Security & Privacy. (I have no clue how/why this works, but it seems to.)


Object Specifiers

In AppleScript, the way an object is referred to is called the object specifier. In your code, you are using the name specifier.

Try a numeric value for the menu item, such as:

click (menu item 12) of menu "Window" of menu bar 1

Or a relative term, such as:

click the last menu item of menu "Window" of menu bar 1