4 Replies Latest reply on Oct 8, 2015 10:11 AM by fentonjones

    Using shell script to show custom dialog

    dyb

      I'd like to run a script that would check if a folder exists and depending on the results i would like to execute another script step.

       

      1. Script Step – Perform AppleScript:

       

      Let ([Qmk = "\""; QmkAS = "\\\""];

      "do shell script " & Qmk & "if [ -d " & QmkAS & "/SEARCHED_FOLDER/" & QmkAS & " ] ; then WHATSTHESTATUS ; fi" & Qmk)

       

      I would like to save some information somewhere (i have no clue) if the script succeeded. Depending on the results i would like to run another script step:

       

      2. Show Custom Dialog that the folder exists or not – if WHATSTHESTATUS = "yes" – for example.

       

      How can i do that? Is it possible to retrieve some values from the if statement in the "do shell script" command? I would use Get(LastError) But there no errors after that script whether the folder exists or not...

        • 1. Re: Using shell script to show custom dialog
          coherentkris

          You might want to check out the free BaseElements plug in function

          BE_FileExists ( path )

          Functions · GoyaPtyLtd/BaseElements-Plugin Wiki · GitHub

          • 2. Re: Using shell script to show custom dialog
            dyb

            Thanks! But i would really like to omit plugins.

            • 3. Re: Using shell script to show custom dialog
              erolst

              Put the result of the shell script into an AppleScript (script …) variable; use a block like

               

              tell "Filemaker Pro {Advanced}"

              set cell "abc" of Table "XYZ" to myShellScriptResult

              -- since AS is a “read-only language”, I can't remember exact object & syntax

              -- please look it up in the FM AS dictionary …

              end

               

              to write into a global FileMaker field (I always have a global ASresult field in one table), and use that to have your FM script branch as desired.

              • 4. Re: Using shell script to show custom dialog
                fentonjones

                I'm not real good at such these days (age), but I have lots of files with pieces about things. I've got a couple of methods to do this test (or similar). I just wrote the "folder path" in manually; so I'll just post what I have.

                 

                The below can be run via AppleScript Editor. You'd need something more to add them to FileMaker.

                 

                Your original method needed something to tell it what the result was. I just used: printf

                I then used regular AppleScript (which I know better than Unix) to check what was returned.

                 

                do shell script "if [ -d ~/desktop ] ; then

                printf 'directory'; fi"

                -- no error, "" returned if false

                if result is "directory" then

                  set folder_test to "exists"

                else

                  set folder_test to "missing"

                end if

                display dialog "Folder " & folder_test buttons {"OK"} default button 1

                 

                 

                This 2nd method used a simpler Unix test.

                 

                -- Folder

                set aFolder to "~/desktop"

                 

                try

                  do shell script "test -d " & aFolder

                  set folder_test to "Folder exists"

                on error

                  set folder_test to "Folder missing"

                end try

                 

                display dialog folder_test buttons {"OK"} default button 1