Re: Manipulate menu items from FrontEnd?
- To: mathgroup at smc.vnet.net
- Subject: [mg80704] Re: Manipulate menu items from FrontEnd?
- From: ragfield <ragfield at gmail.com>
- Date: Wed, 29 Aug 2007 04:20:31 -0400 (EDT)
- References: <fb0ehp$e5c$1@smc.vnet.net>
On Aug 28, 1:15 am, "W. Craig Carter" <ccar... at mit.edu> wrote:
> Hello,
> Does anyone know how to (or if it possible) to manipulate
> menu items from within the frontend? On a macintosh?
>
> I have a series of tasks where I am doing repetive
> pull-downs from menu items, selections, and confirmations.
>
> For example, I'd like to create a palette to do:
> File->Printing Settting->Printing Environment->MySelection
Just have the button evaluate the following code:
SetOptions[InputNotebook[],
PrintingStyleEnvironment -> "MySelection"]
All menu items in Mathematica can be programatically invoked
similarly. Check out this file to get a better idea of how to do
this:
ToFileName[{$InstallationDirectory, "SystemFiles", "FrontEnd",
"TextResources", "Macintosh"}, "MenuSetup.tr"]
Additionally, on Mac you can use AppleScript to do this:
tell application "Mathematica" to activate
tell application "System Events"
click menu item "MySelection" of menu of menu item "Printing
Environment" of menu 1 of menu item "Printing Settings" of menu "File"
of menu bar 1 of application process "Mathematica"
end tell
You can run AppleScript code from within Mathematica using the
'osascript' command line program like this:
Run["osascript -e '" <>
"tell application \"Mathematica\" to activate
tell application \"System Events\"
click menu item \"MySelection\" of menu of menu item \"Printing \
Environment\" of menu 1 of menu item \"Printing Settings\" of menu \
\"File\" of menu bar 1 of application process \"Mathematica\"
end tell" <> "'"]
-Rob