Help with an AppleScript - click a menu item which has a name which changes I'd like to make F5 be equivalent to clicking on the mail icon in the taskbar, and F6 equivalent to clicking minimise on the mail app main window (or the 'hide' action).  Is there a way to achieve this?
I'm following the method here.
Below is my script which almost works.
The problem is I'm clicking a menu item the name of which is not constant.
on run {input, parameters}
    
    tell application &quot;System Events&quot;
        tell process &quot;Mail&quot;
            set frontmost to true
            -- &quot;Inbox (8 Messages)&quot; will only work when 8 messages!:
            click menu item &quot;Inbox (8 Messages)&quot; of menu &quot;Window&quot; of menu bar 1
        end tell
    end tell
    
    return input
end run
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 &quot;Window&quot; of menu bar 1

Or a relative term, such as:
click the last menu item of menu &quot;Window&quot; of menu bar 1