4 Replies Latest reply on Jan 20, 2012 1:25 PM by Polarpro

    Using Applescript to mount a volume from a FileMaker script

    Polarpro

      Hello,

       

      I wrote a fairly simple Applescript that 1. mounts a volume and 2. exports a set of records to the desired folder there.

      The FileMaker script step contains only a single line ("mount volume ...")

       

      So far things have worked well, but I'd like to make sure that the FileMaker script steps that follow the mounting process only get executed if the volume really got mounted. In case the mounting fails I'd like to cover this with my own error handling.

       

      Does anybody know if there is an easy way to implement this? I am not the most experienced Applescript programmer.

       

      Thanks you,

      Mike

        • 1. Re: Using Applescript to mount a volume from a FileMaker script
          RayCologon

          Hi Mike,

           

          To have your script figure out if the drive has been mounted, I suggest that you use a subsequent Perform AppleScript[ ] script step to call a line of shell script such as:

           

          do shell script "/bin/ls /Volumes"

           

          which will return a list of mounted volumes, and you can then run a PatternCount( ) across the result to determine if the drive name (of the drive that should previously have been mounted) is in the list, and branch accordingly.

           

          Regards,

          Ray

          ------------------------------------------------

          R J Cologon, Ph.D.

          FileMaker Certified Developer

          Author, FileMaker Pro 10 Bible

          NightWing Enterprises, Melbourne, Australia

          http://www.nightwingenterprises.com

          ------------------------------------------------

          • 2. Re: Using Applescript to mount a volume from a FileMaker script
            sporobolus

            on 2012-01-19 10:44 Polarpro wrote

            I wrote a fairly simple Applescript that 1. mounts a volume and 2. exports a set of records to the desired folder there.

            The FileMaker script step contains only a single line ("mount volume ...")

             

            So far things have worked well, but I'd like to make sure that the FileMaker script steps that follow the mounting process  only get executed if the volume really got mounted. In case the mounting fails I'd like to cover this with my own error handling.

             

            Does anybody know if there is an easy way to implement this?

             

            AppleScript's "list disks" command returns the name of every mounted volume;

            you can test whether the name of your volume is in the list:

             

            set my_volume to "foo"
            set the_volumes to list disks
            if my_volume is in the_volumes then
               -- the volume is mounted
            else
               -- the volume is not mounted
            end if
            

             

            • 3. Re: Using Applescript to mount a volume from a FileMaker script
              pkgibbs

              Another way that I like is:

               

              tell application "Finder"

                        if not (exists folder "foldermountname") then

                                  try

                                            mount volume "smb://192.168.1.100/foldermountname" as user name "user" with password "mypassword"

                                  on error "Failed to connect to foldermountname" number 1001

                                  end try

                        end if

              end tell

              • 4. Re: Using Applescript to mount a volume from a FileMaker script
                Polarpro

                Thanks a lot for your input,

                I now use:

                 

                set my_volume to "foo"

                set the_volumes to list disks

                if my_volume is not in the_volumes then

                    try

                        mount volume "smb://192.168.1.100/foldermountname" as user name "username" with password "password"

                    end try

                end if

                 

                This is the solution that seems to work fastest (the spinning wait cursor still shows up though for a little while.) Furthermore, as I am not the most experienced AppleScript writer, I decided to go for a solution that contains just a minimum of code.

                 

                The Perform AppleScript script step is followed by an Export records script step. Only if the records were not exported (due to failed mounting or whatever) a FileMaker error message is shown (Error 800).

                 

                Thanks again!

                Mike