7 Replies Latest reply on Jul 19, 2012 6:47 PM by fmp

    Passing user entered variables to Applescript

    strngr12

      Hello,

       

      I need users to be able to pass their username and password through Applescript to terminal. In a nutshell, I need to do this:

       

      Set Variable [$userName; Value: asks for user input]

      Set Variable [$userPassword; Value: asks for user input]

       

       

      Later in script...

       

       

      Perform AppleScript ["do shell script" & "echo " & Quote ( $userPassword) & "|" command -u" & Quote ( $userName ) & "--argument --noconsole"]

       

      My question is, how do I get a popup window to ask the user to enter the commands and is it possible to get a pop up window to gather both variables at once?

       

      Thanks!

       

      -Dan

        • 1. Re: Passing user entered variables to Applescript
          snsanders

          This will do what you want:

           

          24U Appearance OSAX 4.0

          http://www.24usoftware.com/AppearanceOSAX

           

          It is very similar to their display plugin for FMP.

           

          Steven

          • 2. Re: Passing user entered variables to Applescript
            strngr12

            Thanks for the reply, but this doc will be distributed widely and even mixed down to runtime apps so I don't want to ask anyone using to install any additional software.

            • 3. Re: Passing user entered variables to Applescript
              comment

              strngr12 wrote:

               

              My question is, how do I get a popup window to ask the user to enter the commands and is it possible to get a pop up window to gather both variables at once?

               

              There is no way for users to enter values directly into variables; use global fields intead.

               

              The Show Custom Dialog [] script step allows you to present up to three input field to the user. You also get the choice to format a displayed field for password entry (i.e. showing ******* during entry).

               

              Don't forget to clear the globals before and/or after each use.

              • 4. Re: Passing user entered variables to Applescript
                strngr12

                Thanks Michael.  I'll try that.

                • 5. Re: Passing user entered variables to Applescript
                  strngr12

                  Hello Michael,

                   

                  Can you tell lme how to clear the fields?  I've tried "clear," "Replace Field Contents," and a couple other things but when I'm in debugger and step past those options the last value entered still remains in data viewer even when I refresh values.

                   

                  Also, to be clear, I have a lot of globals so I don't want them all to go.  I need the others to remain.

                   

                  Thanks for your help.

                  • 6. Re: Passing user entered variables to Applescript
                    comment

                    Try:

                     

                    Set Field [ SomeTable::gGlobalField ; "" ]

                    • 7. Re: Passing user entered variables to Applescript
                      fmp

                      Hi, there are two usual ways to get variables into a shell command starting in Filemaker: 1) Use an FM script to call an Applescript and use "Display Dialog" to ask for the info; or 2) use an FM script to call an FM custom dialog which sets fields in FM (usually global fields), after which they are available to an Applescript. To date, I don't believe you can transfer an FM $ variable directly to Applescript.

                       

                      In general, it's easier to use method 2) above. After you set the fields with the info, a subsequent  Perform Applescript step should get the values by telling any layout which actually has those fields on it with the desired info in them (they can be in a tab which is not currently visible, though) like so:

                       

                      -- tell application "Filemaker Pro Advanced" -- "tell app" line not needed when invoked inside FM

                      tell window 1

                      tell layout "Prefs"

                      -- set shell command variables

                      set theUser to (get data cell "gUsername" of current record) as text

                      set thePW to (get data cell "gPassword" of current record) as text

                       

                      --clear fields on Prefs layout if needed

                      set data cell "gUsername" of current record to ""

                      set data cell "gPassword" of current record to ""

                       

                      end tell

                      end tell

                      -- end tell

                       

                      -- use variables above in do shell script

                       

                       

                      *Note: code not proofed