12 Replies Latest reply on Feb 1, 2012 8:06 AM by BruceRobertson

    Get list of filenames from a different server or location using applescript in filemaker.

    lutfishah

      Hi All,

       

      I need a bit of help.

      Basically I'm trying to get list of filenames in a folder from a different server or location into filemaker database by using apple script.

      The apple script is keep on giving me errors with regards to the path (e.g: Can’t get every file of /Volumes/Test_LowRes".)

       

      This is how the apple script looks like.

       

      Screen shot 2012-01-31 at 14.48.10.png
      I'm not good with apple scripts ; )
      I'm using FileMaker Pro 11 Advanced and mac10.6.8.
      Thanks
        • 1. Re: Get list of filenames from a different server or location using applescript in filemaker.
          pminich

          I think that it is in how your are forming the file path. I am by no means an apple script guru but I tend to use the mac friendly form in which case it would look something like "DriveName:Volumes:Test_LowRes".

           

          Set that to a variable as an alias and then use that variable in the line - set x to filenames of variable

           

          I would highly recommend using the Script Master plugin for this if possible. The ListAllFilesInDirectory function returns a value list of the files that you can then do with as you like. Speaking from experience it is a heck of a lot easier than going "outside" filemaker.

          • 2. Re: Get list of filenames from a different server or location using applescript in filemaker.
            BruceRobertson

            Please post your script as text. Nobody is going to re-enter it or test it from your image.

            • 3. Re: Get list of filenames from a different server or location using applescript in filemaker.
              lutfishah

              Many thanks for the replyb pminich : )

               

              I think I do have a script master plugin.

              Would it be possible to give an example of using ListAllFilesDirectory function. I'm using a script in filemaker which "mounts" the

              location of the server on my computer. Then could you tell me what should be my next step.

               

              Thanks

              • 4. Re: Get list of filenames from a different server or location using applescript in filemaker.
                lutfishah

                Oh Sorry

                 

                on filenames from _folder

                 

                          tell application "Finder"

                                    mount volume "smb://192.168.210.12/Test_LowRes"

                                    set _filenames to name of every file of _folder

                                    set _extensions to name extension of every file of _folder

                 

                          end tell

                          set _names to {}

                          repeat with n from 1 to count of _filenames

                 

                                    set _filename to item n of _filenames

                                    set _extension to item n of _extensions

                 

                                    if _extension is not "" then

                                              set _length to (count of _filename) - (count of _extension) - 1

                                              set end of _names to text 1 thru _length of _filename

                                    else

                                              set end of _names to _filename

                                    end if

                 

                          end repeat

                 

                          return _names

                end filenames

                 

                set x to filenames from ("/Volumes/Test_LowRes")

                tell application "TextEdit"

                  activate

                  make new document

                          set _names to {}

                          set text of document 1 to x as text

                 

                end tell


                • 5. Re: Get list of filenames from a different server or location using applescript in filemaker.
                  pminich

                  Here is how I read in a list of file names for fils that are automatically imported into the database. I put the file names into a variable and then enter them into a table.

                   

                  1. Read in all the files in the store directory into a value list

                  Set Variable [ $fileList; Value:ListAllFilesInDirectory( "/Volumes/" & $filePath & "/" & $storeDirectory ) ]

                   

                  #

                   

                  1. Create a table with all the file names in the store directory by looping through the value list of the file listing

                   

                  Go to Layout

                   

                  1. Clear out old entries

                   

                  Show All Records

                   

                  Delete All Records

                   

                   

                  1. Set looping variables

                   

                  Set Variable $numberOfFiles; Value:ValueCount ( $fileList ) Set Variable $fileNumber; Value:1

                  Loop

                   

                  New Record/Request

                  Set Field [ ImportFiles_imprtfls::ImportFile_lxt; // GetValue ( $fileList ; $fileNumber )

                   

                  Let ( [ rawFile = Substitute ( GetValue ( $fileList ; $fileNumber ) ; "/" ; ¶ ) ; count = ValueCount ( rawFile ) ] ;

                   

                  GetValue ( rawFile ; count ) ) ]

                   

                  Commit Records/Requests

                   

                  Set Variable $fileNumber; Value:$fileNumber + 1 Exit Loop If

                   

                  End Loop

                   

                   

                  • 6. Re: Get list of filenames from a different server or location using applescript in filemaker.
                    BruceRobertson

                    You are not referring to the folder properly.

                     

                    every file of folder _folder


                    • 7. Re: Get list of filenames from a different server or location using applescript in filemaker.
                      BruceRobertson

                      on filenames from _folder

                       

                                tell application "Finder"

                                          set smbdrive to "smb://192.168.210.12/Test_LowRes"

                        -- or send user name and password

                        -- set smbdrive to "smb://username:password@192.168.210.12/Test_LowRes"

                       

                        mount volume smbdrive

                                          set _filenames to name of every file of folder _folder

                                          set _extensions to name extension of every file of folder _folder

                                end tell

                       

                                set _names to {}

                                repeat with n from 1 to count of _filenames

                       

                                          set _filename to item n of _filenames

                                          set _extension to item n of _extensions

                       

                                          if _extension is not "" then

                                                    set _length to (count of _filename) - (count of _extension) - 1

                                                    set end of _names to text 1 thru _length of _filename

                                          else

                                                    set end of _names to _filename

                                          end if

                       

                                end repeat

                       

                                return _names

                      end filenames

                       

                      set targetFolder to "Test_LowRes"

                      -- use colons for subfolders

                      -- set targetFolder to "Test_LowRes:subfolder"

                       

                      set x to filenames from targetFolder

                       

                      tell application "TextEdit"

                        activate

                        make new document

                                set AppleScript's text item delimiters to return

                                set text of document 1 to x as text

                      end tell

                      • 8. Re: Get list of filenames from a different server or location using applescript in filemaker.
                        ch0c0halic

                        May have bit off more than a few file,

                         

                        "file://Volumes/Test_LowRes" is not a valid path.

                        First, using "file://" is not acceptable, its a folder.

                        Second, the Mac OS is Unix and it uses ":" colons in the path.

                         

                        I'd try using:

                        ":Volumes:Test_LowRes:"

                         

                        Or maybe just ":Test_LowRes:" since this is the mounted location.

                         

                         

                        My code looks like this and results in the field "gdestination_folder_contents" having a list of file names from the "Shared" folder on my hard drive. I haven't tried it for a mounted volume. However, I think it will work the same.

                         

                        tell application "Finder"

                        set oldDelimiters to AppleScript's text item delimiters

                        set AppleScript's text item delimiters to return

                        set gdestfile to name of entire contents of folder "my_computer:Users:Shared:" as text

                        set AppleScript's text item delimiters to oldDelimiters

                        end tell

                        set cell "gdestination_folder_contents" to gdestfile

                        • 9. Re: Get list of filenames from a different server or location using applescript in filemaker.
                          BruceRobertson

                          You're mixing up UNIX and Finder.

                           

                          FINDER uses colons in the file path.

                           

                          The underlying UNIX uses POSIX paths, which use /

                          • 10. Re: Get list of filenames from a different server or location using applescript in filemaker.
                            lutfishah

                            It worked for me : )

                             

                            Many thanks BruceRobertson. One more thing that if I wanna get the filenames in the folder and the sub-folders at the same time then what needs to be added on the above script.

                             

                            really appriciate your help.

                             

                            Thanks

                            • 11. Re: Get list of filenames from a different server or location using applescript in filemaker.
                              pminich

                              To do this you will need to check for any nested folders inside the

                              original folder. I would do this by recursively calling a handler to do the

                              heavy lifting.

                               

                              This is a fair bit more involved. There is a script master function that

                              would handle this very nicely - GetAllFilesRecursively provides the files

                              in a value list with the path to each.

                               

                              -- iPad

                              Pete Minich

                               

                               

                              Direct/FaceTime/Text - 781.223.8884

                               

                               

                              This e-mail transmission contains information that is confidential and may

                              be privileged. It is intended only for the addressee(s) named above. If you

                              receive this e-mail in error, please do not read, copy or disseminate it in

                              any manner. If you are not the intended recipient, any disclosure, copying,

                              distribution or use of the contents of this information is prohibited.

                              Please reply to the message immediately by informing the sender that the

                              message was misdirected. After replying, please erase it from your computer

                              system. Your assistance in correcting this error is appreciated.