Force an app to run one of its menu options from a shell script? Is there any way to force the App to run one of its menu options if there is no command line interface available?

Perhaps an Automation sort of thing?

EXAMPLE

I would like to run NewsFire's "File > Export Feeds" command to backup the feed list (OPML file). I tried running NewsFire through Terminal with "--help" but no luck.

Here is the backup script I currently use, in case anybody find it useful. It can be used to save and restore the state of NewsFire accross multiple machines (to restore you just cd ~ , and then unzip backup.zip).

#! /bin/bash
#
# Backup NewsFire preferences, feeds and cache (everything)
#

D_DESTFILE=~/Backups/Config/NewsFire.zip

# Don't update archive, create new one
if [ -e "$D_DESTFILE" ]; then
  rm $D_DESTFILE
fi

cd ~
zip -r $D_DESTFILE Library/Application\ Support/NewsFire Library/Caches/org.xlife.NewsFire Library/Preferences/org.xlife.NewsFire.plist
This is a beginning of an AppleScript to do the exporting:

set filename to "test file"

tell application "NetNewsWire" to activate
tell application "System Events"
    tell process "NetNewsWire"
        click menu item "Export Subscriptions…" of menu "File" of menu bar 1
        set value of first text field of first sheet of first window to filename
        click button "Save" of first sheet of first window
    end tell
end tell

tell application "NetNewsWire" to quit


It will save the exported file with the set filename at the location which was last used to do the exporting. It will not overwrite a currently existing file, so maybe you can save it in a temporary place and move it with a separate script.

Note: My copy of NetNewsWire had the menu command "Export Subscriptions…", not "Export Feeds", but if yours is different, just change the name of the menu item on line 6.

Edit to add: You also need to have "Enable access for assistive devices" in the Universal Access System Preference Panel set to enabled for this to work.