Update graph macro with applescript

I'd like to update graph macros with a single keystroke, and wrote a short applescript for use with Keyboard Maestro:
tell application "Igor Pro" Do Script " String/G win=WinName(0,1); DoWindow/R $win;" end tell

The command "String/G win=WinName(0,1); DoWindow/R $win" works fine from the Igor Command Window, but does not work from the script if run from AppleScript Editor or from Keyboard Maestro. Any suggestions on how to make this work?
I know almost nothing about apple script so I can't directly answer your question, but for this to work you'd need to have Igor execute that code but your apple script isn't doing that.

There's probably a better way to do this, however.

I'd create a simple function in a stand alone procedure file which calls DoWindow/R. Then add a user defined menu definition that calls the function, like this:

Menu "Graph"
    "Save Recreation Macro/1",/Q,MyRecreationFunction()
End

Function MyRecreationFunction()
    String wName = WinName(0, 1)
    String cmd = ""
    sprintf cmd, "DoWindow/R %s", wName
    Execute/Z/P/Q cmd
End


After you save this procedure file, create a shortcut/alias to the file and put that into the Igor Procedures folder within your Igor Pro 6 User Files folder (if you're using Igor 6.10 or later) or your Igor Procedures folder in the Igor Pro application folder if you're using an earlier version of Igor. Doing this makes sure that the procedure file will be included whenever you open Igor, so the shortcut will be available. Adding the "/1" in the menu definition means that Ctrl-1 will activate the menu item. You can use other combinations as well.
scb wrote:
I'd like to update graph macros with a single keystroke, and wrote a short applescript ... Any suggestions on how to make this work?


The recommendation that Adam Light has made is the better option. What you have requested to code is a call from Igor Pro to invoke AppleScript to activate Igor Pro to do something. Alternatively, you are coding something that you would have to execute by being outside of the Igor Pro application itself (ie, as an applet). The former still requires that you code a one character key to execute the function in Igor Pro that will execute the AppleScript from Igor Pro that will subsequently re-activate Igor Pro in order to execute a second function that will do the graph actions you want (see the complications!). The latter means that you leave the Igor Pro application, which defeats the purpose of having a one character command within Igor Pro in the first place.

Perhaps you are wanting to code this so that you can send the request from a different application than Igor Pro using AppleScript as the conduit. In this case first code a function in Igor Pro to do all the changes needed in Igor Pro. Then, code an AppleScript to activate Igor Pro and run that function. This way, you can update the function in Igor Pro and need not muck around in AppleScript any further.

HTH

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Thanks for the great suggestions. This is definitely a better approach, though I still think the applescript should work. In fact, I had a bunch of other applescripts set up to change the graph expansion using AppleScript code like
tell application "Igor Pro"<br />
    Do Script "ModifyGraph expand=2"<br />
end tell


This script does in fact work. However, now I've replaced those applescripts with entries in the same procedure file suggested above:
Menu "Graph"
    "Update Graph Macro/G",/Q,MyRecreationFunction()
    "Expand 1/1",/Q,ModifyGraph expand=1
    "Expand 2/2",/Q,ModifyGraph expand=2
    "Expand 3/3",/Q,ModifyGraph expand=3
End


I used command-G for the keyboard equivalent of "Update Graph Macro" to avoid conflict with "Expand 1".