Skip navigation
BigGunN
Currently Being Moderated

ScriptUI run script from dialog button

Mar 19, 2012 7:54 PM

Here is what I have right now.  It is a little clunky in the way it works, and I would just like to make it a bit slicker.

 

I have a script on startup that creates a Menu item with a dropdown submenu item. when you click on the submenu item, it starts a script. 

The first thing the script does is pop up a message box that tells them that two dialog boxes are going to popup. The first one asking them to choose the location of an xml file and the second dialog box that ask them to choose the location of their image folder.  After they finish choosing their folder in the second dialog, the script takes those two values, makes them variables, and continues to run the rest of the script. 

 

 

Here is what I would like it to do..

1. open a dialog window with two input fields, two "browse" buttons, and OK and CANCEL buttons

2. when you click the first browse button next to the first input field, it will open a file dialog window.  You select your file and the file string will populate the input field

3. when you click the second button next to the second input field, it opens a folder dialog window.  You select the folder and the string populates the second input field.

4. when you click OK, it feeds the values in the input fields to a script.

 

I already have scripts to that open the file and folder dialogs, but what I can't figure out  how to do is to start and run a script from a button press, in this case, when the OK button is pressed.  It is probably an onClick, but I haven't been able to find any examples of what the syntax would be. 

 

The closest I have found is in the Beginning ScriptUI document that was on Jongware's site, in the section on Communication between windows.  But that opens each of the windows with a different script and not using a button press to call a script.

 

As always, any point in the right direction is very much appreciated. thanks.

 
Replies
  • Currently Being Moderated
    Mar 20, 2012 12:31 PM   in reply to BigGunN

    > It is probably an onClick

     

    It is indeed. You were looking in the wrong place in that guide. Look in the section "Responding to button presses".

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2012 4:48 PM   in reply to BigGunN

    Instead of $.evalFile(), use app.doScript(), in which you can specify a script language. I believe the form is something like this:

     

    app.doScript (Script1, ScriptLanguage.VISUAL_BASIC);

     

    but do check the object-model viewer to check the correct form.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 21, 2012 4:11 PM   in reply to BigGunN

    ScriptUI windows and the JS file dialog boxes don't communucate. To get a return value from a file dialog, you'd do something like this:

     

    myFile = Folder (myFolder).openDlg ("Select some files");

    if (myFile === null)

       // return, do nothing

     

    The JavaScript Tools Guide CSx (see the ESTK's Help menu) documents several file and folder selection dialogs.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 22, 2012 8:18 AM   in reply to BigGunN

    I think what your looking for is the value from entry in the text field? To get this value after the window closes you would use your variable name that you created the entry field with.

    So it would be something like this i think. var myColors=myColorsFieldOne.text; myColorsFieldOne being the dialogs variable.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2012 8:58 AM   in reply to BigGunN

    This may help in passing your variables to anothe script. I used this little snippet(not my own) to have entry fields remember what the user typed in the last time they ran the dialog. This may help you write to another script. This one rewrites itself.

     

    var schlNamePos = 1002 ;

        var updateFile = function(n){

        var f = File(app.activeScript);

        if ( f.open('e') ){

            f.seek(schlNamePos);

            f.write(''+n);

            f.close();

            }

        }

    updateFile(mySchoolName);

     
    |
    Mark as:
  • John Hawkinson
    5,512 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 23, 2012 9:06 PM   in reply to BigGunN

    The problem that I am running into is that the file and folder dialogs don't give me an absolute path, but a path that is relative to the startup disk.  It is discussed in this post and I haven't found any way to get around it yet.  From the discussion, it doesn't sound like there is a work around, so I may just be out of luck in trying to do what I want to do.  But I am going to keep trying for a bit longer.

    I think that thread is somewhat confused about how file path works, and also that is Mac OS -specific. Can you please give a very specific example of the problematic file path? With real actual values and show how it is a problem?

     

    (Environment variables? Wow. I would have hoped there was a better way. But I'm not a VB programmer.)

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 24, 2012 1:42 AM   in reply to BigGunN

    As I said earlier, read up on files in the JavaScript Tools Guide CSx guide (ch. 3, File system access). You'll read there, for instance, that ~ is the desktop, and that /c/dir is the platform-independent notation for c:\dir. And as John mentioned, environment variables are not necessary (and should maybe not be used for your purpose at all). Instead, you can write script data to a disk file, or use an application or a document label.

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2012 1:05 PM   in reply to BigGunN

    For the app:

     

    app.insertLabel("foo", "my info");

    app.extractLabel("foo");

     

    For a doc:

     

    myDoc.insertLabel etc.

     

    HTH,

    Ariel

     
    |
    Mark as:
  • John Hawkinson
    5,512 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 26, 2012 2:18 PM   in reply to BigGunN

    BigGunN: sorry for the delay, I've been swaaaaamped lately.

     

    When I choose a folder, like    MyDocuments/My Pictures  I get this returned..     ~/Documents/My%20Pictures

     

    Are you looking at the .fsName property? It's not convenient for me to test under Windows right now, but on a Mac,

     

    >> f=File.openDialog()

    ~/Desktop/frap.pdf

    >> f.fsName

    /Users/writer/Desktop/frap.pdf

    >> f.absoluteURI

    ~/Desktop/frap.pdf

    So, don't use absoluteURI. Does that fix it for you?

     

    With respect to passing arguments, I'm afraid I have to disagree with Peter and Ariel:

     

    And as John mentioned, environment variables are not necessary (and should maybe not be used for your purpose at all). Instead, you can write script data to a disk file, or use an application or a document label.

     

    That's even worse then using an environment variable -- it's active bad if you might have multiple simultaneous button presses being happening at the same time, for instance.

    Instead, I would expect the right solution is to call your VB with arguments, formal parameters that are passed from one function to another. But environment variables are OK. They are just more effort than they need to be and kind of ugly. But they're functional. I'd leave them be until you have something that works and only then worry about clean-up.

     
    |
    Mark as:
  • John Hawkinson
    5,512 posts
    Jun 25, 2009
    Currently Being Moderated
    Mar 26, 2012 4:16 PM   in reply to BigGunN

    Well, VB is Microsoft-only. So if your scripts use VB, there is no way they will work on a Mac.

    With respect to Javascript, unless you use obviously platform-specific features, your script should be portable. I wasn't quite sure about the filesystem specifics.

     

    I'm not sure how you refer to arguments in VBScript. I beleive there are several examples in the documentation, bt I don't have time to go look around for the mright now.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points