3 Replies Latest reply on Jul 27, 2017 2:00 AM by Jens Teich

    Create Subfolders in my current .fmp12 directory

    SONICARC

      Hello,

      I’m trying to create a script where i can get the file path of the current .fmp12 file and in that same directory create several subfolders that will be named in the same script.

       

       

      I’ve seen lots of examples online that utilise AppleScript syntax that looks at the System Desktop or `Documents folder rather than the directory folder that holds the fmp12 file.

       

       

      I know how to solve this problem by using Get (Directory), but I have to manually name each new folder one at a time.

       

       

      I managed another workaround that uses the following Native AppleScript:

       

      set folderpath to POSIX path of (choose folder with prompt "Select client folder")

      do shell script "mkdir -p " & (quoted form of (folderpath )) & "{\"Payments\",\"Overdue\",\"Attendance\",\"Personnel\"}"

       

      Again, I initially have to manually navigate to the directory folder where my .fmp12 file resides in order to auto-create the sub-folders in the script.

       

       

       

      So far, I have a created a var that gets the fmp12 holding directory and adds a Reports folder that will then contain my subfolders (this might be wrong)

       

      Set Variable [ $fmpPath ;

      Value: Let ( [ filePath = Middle ( Get ( FilePath ) ; 6 ; Length ( Get ( FilePath ) ) ) ;

                LeftPath = Left ( filePath ; Position ( filePath ; Get ( FileName ) ; 1 ; 1 ) - 1 )

              ] ; LeftPath & "Reports/" )

       

       

      but trying to create a set of subfolders within the newly created Reports folder using a Calculated Perform AppleScript, leaves me stumped.

       

       

      A non-plugin solution will be much appreciated and teach me what I simply cannot fathom at this stage.

       

      (I'm using FMP 15 Advanced with OS Sierra 10.12.6)

        • 1. Re: Create Subfolders in my current .fmp12 directory
          Jens Teich

          In case you work with FM Advanced, open tools > data viewer and evaluate your AppleScript code.

          If you do not have FMAdv you will have to create an additional calc field for that.

          Open AppleScript Editor App and paste code in fresh window.  Run it (CMD-R) and see what happens.

          You might go one step further and paste content of 'do shell script' into Terminal App and see what that gives.

          Paste results of these two actions here.

          2 of 2 people found this helpful
          • 2. Re: Create Subfolders in my current .fmp12 directory
            SONICARC

            Cheers for the heads up JensT.

             

            For now, I'm just going to stick with a Native AppleScript script as follows:

             

            Perform AppleScript [

            set folderpath to POSIX path of (choose folder with prompt "Select the Folder that contains the FM file")

            do shell script "mkdir -p " & (quoted form of (folderpath )) & "{\"Payments\",\"Overdue\",\"Attendance\",\"Personnel\"}" ]

             

            In my limited knowledge and time available to research any further for now, the AppleScript   syntax does not allow you to reference a file path contained in an  FM variable by 'path to'. Therefore 'choose folder' with a manual nav to the folder that contains the .fmp12 file is no biggy as this only has to be done once anyway. Reason being, I want the client to generate folder names as prescribed in the curly braces {... } and alleviate user typos.

             

            If anyone knows a nice way in a native / calculated AppleScript  or otherwise in FM, to automatically direct the Get (filepath) to the folder that contains the .fmp12 file  when that path is collected via a var...

             

            e.g. Set Variable $path;

            Let ( [ filePath = Get ( FilePath ) ;

                      LeftPath = Left ( filePath ; Position ( filePath ; Get ( FileName ) ; 1 ; 1 ) - 1 )

                    ] ; LeftPath )

             

            resulting in for example: file:/MySystemHD/Users/MySystemHD/Documents/ClientBusiness/FilemakerFolder/

            which AppleScript  will interpret as:

            "\"file:/MySystemHD/Users/MySystemHD/Documents/ClientBusiness/FilemakerFolder/\"" and screw things up due to file type as text error and it seems incompatibility with the  'path to' command

             

            then that would be super cool to know.

             

            In the meantime, I'm going to crack on and settle for a manual prompt via the choose folder command in native AS to then auto gen the sub-folder names.

             

            Cheers.

            • 3. Re: Create Subfolders in my current .fmp12 directory
              Jens Teich

              You are looking for the path of your active database?  This would be Get( FilePath )