Is there a Terminal command to open a Mac menu bar item? Suppose I want to open a specific app which has an icon on the menu bar tray, is it possible to do it using a shell command? 

In my case, there is an app called "Quick View Calendar" (available in Mac App Store) which shows up in the Menu bar, which I would like to open with a Terminal command and to use that code to run an Automator service to
Since all that's required is a single click to the menu bar icon in order to open the app, AppleScript can achieve this very easily using GUI scripting, which requires the right accessibility permissions to be granted to whichever program you'll use to execute the AppleScript (e.g. Script Editor, Automator, Terminal, etc..).

So, first, grant the appropriate permissions via System Preferences.  This screenshot is from MacOS 10.13:



After this is done, open up Script Editor and run this script.  I don't have Quick Calendar View myself, but the principles for most menu bar apps are the same, so this will hopefully obtain a list of application names that have icons sitting in your menu bar:

    tell application "System Events" to get the name of ¬
        every process whose class of menu bar 2 is menu bar 


"Quick View Calendar" or something appropriately similar ought to appear in the list that is returned by running that command.  This is the name that I've used in the following snippet, which is what actually does what you need, namely to issue a mouse click to the menu bar icon and open the application.  If the name is something different, you can change that yourself:

    tell application "System Events" to tell process "Quick View Calendar" to ¬
        click menu bar item 1 of menu bar 2


You can paste this code into a Run AppleScript action in Automator (again, provided Automator has been granted accessibility permissions), which will then become part of your workflow in creating the service you want to create.

Your original request was to run a command from Terminal to perform this action, so you can simply open up Terminal (again, accessibility permissions!), and type this:

    osascript \
        -e 'tell application "System Events" to ¬' \
        -e 'tell process "Quick View Calendar" to ¬' \
        -e 'click menu bar item 1 of menu bar 2'


If you run into any problems, let me know.