Select Service as the type of template to use for your new Automator task, and click the Choose button.
In the Library pane, make sure Actions is selected, then underneath the Library item, click Utilities. This will filter the available workflow types to just those relating to utilities.
In the filtered list of actions, click Run Shell Script and drag it to the workflow pane.
At the top of the workflow pane are two drop-down menu items. Set the Service receives selected to files or folders. Set the in to Finder.
Copy the entire shell script command that we created below, and use it to replace any text that may already be present in the Run Shell Script box.
From the Automator file menu, select Save, and then give the service a name.
The name you select will appear as the menu item. I call mine Toggle Hidden Files.