1 2 Previous Next 21 Replies Latest reply on Sep 21, 2016 1:43 PM by justinc

    Exit script

    tays01s

      I've a 'Create Folder' script for Mac/PC. I'd like to exit it where folder already exit to avoid unnecessary dialogues. I've tried:

      If(

      not IsEmpty (

      Get(DesktopPath)/Folder & "sub_folder_1/" and

      Get(DesktopPath)/Folder & "sub_folder_2/"

      )

      Exit script[]

      Else

      CreateFolder lines

      End if

       

      But the script now fails to create folders even if they are missing. So I'm obviously missing something?!

        • 1. Re: Exit script
          hbrendel

          Get ( DesktopPath ) & <whatever else> will never be empty, because the result is at least the name of your Desktop Path.

           

          BTW what would the result of Get(DesktopPath)/Folder be? I'd think FM would try to divide two text values and evaluate this to "?" which also is not empty.

           

          Also you are not making proper use of "AND" within an If statement.

           

          What script steps do you use to create the folder?

          • 2. Re: Exit script
            wimdecorte

            The IsEmpty does not check if the folder exists or if it has content, it just checks wether the string that results from "Get(DesktopPath)/Folder & "sub_folder_1/" has a value.

            And it always has a value so it is never empty and so your exit step is always executed.

             

             

            • 3. Re: Exit script
              tays01s

              Ah! So putting a general Q then, how would you check whether a Desktop/folder/subfolder exists or not?

              • 4. Re: Exit script
                scottworld

                I don't think you can do this natively within FileMaker. You will probably need to use another language like AppleScript, or use a plug-in like the Troi File plug-in.

                 

                Alternatively, is it required for these folders to be user-accessible? If not, you can always use the Get (TemporaryPath) function to write your files into the temporary folder. The contents of this hidden folder automatically get deleted after the user quits out of FileMaker Pro.

                • 5. Re: Exit script
                  tays01s

                  Thanks. I think I'll have to put up with not checking in this instance, but the plug-in or TempPath are both good ideas for other situations.

                  • 6. Re: Exit script
                    nicolai

                    I know it was already flagged as resolved, but I would like to disagree. I managed to achieve the same thing with no plugins. I found the initial code on StackOverflow and modified it quite a bit, sorry, I have no link to the original post.

                     

                    Here it is done for one folder, you can add as many as you want:

                     

                     

                    set myFolder to "Client files"

                    set desktoppath to (path to desktop from user domain) as string

                    set targetfolder to desktoppath & myFolder

                    tell application "Finder"

                      if not (exists folder targetfolder) then

                      make new folder at folder desktoppath with properties {name:myFolder}

                      end if

                    end tell

                    • 7. Re: Exit script
                      scottworld

                      That is an AppleScript, which is precisely what I said in my original post: that AppleScript is a solution. You would need to use the "Perform AppleScript" script step to process that code within FileMaker.

                      • 8. Re: Exit script
                        nicolai

                        Yes, sorry, missed that. Looking at the OP, it has to be PC compatible, so he would need VBScript solution as well.

                         

                        A plugin could be a better option for cross-platform solution. I would recommend Base Elements, as it is free (sorry, Troi).

                         

                        You would use BE_FileExists to check if a folder exsists and BE_CreateFolder for creating a folder

                         

                        Nicolai

                        • 9. Re: Exit script
                          tays01s

                          I have so far avoided BE/ plug-ins generally because:

                          1. Maintenance issues: I was previously advised that you need different plug-ins for Mac and 32 & 64-bit PC.

                          2. Finding folder path: I need this to use BE_FileExists and as you say it needs to be the OS filepath, not the FM filepath. However, currently I it's only via FM get(DesktopPath) that I can get this path. How do I find OS filepaths from unknown Mac/PC/ iPad (may in future) users?

                          • 10. Re: Exit script
                            monkeybreadsoftware

                            Not sure about BE plugin, but MBS Plugin has a function to convert paths: Path.FileMakerPathToNativePath

                            • 11. Re: Exit script
                              monkeybreadsoftware

                              So in MBS Plugin:

                               

                              Set Variable [$folder; Value:MBS( "Folders.UserDesktop" )]

                              Set Variable [$path; Value:MBS( "Path.AddPathComponent"; $folder; "your file name" )]

                              Set Variable [$r; Value:MBS("Files.CreateDirectory"; $path)]

                               

                              That can create a folder on the desktop.

                              • 12. Re: Exit script
                                wimdecorte

                                tays01s wrote:

                                 

                                I have so far avoided BE/ plug-ins generally because:

                                 

                                2. Finding folder path: I need this to use BE_FileExists and as you say it needs to be the OS filepath, not the FM filepath. However, currently I it's only via FM get(DesktopPath) that I can get this path. How do I find OS filepaths from unknown Mac/PC/ iPad (may in future) users?

                                 

                                You can still use the FM Get() function to get the desktop path, then change the syntax to fit the OS.  It's very straightforward.

                                • 13. Re: Exit script
                                  tays01s

                                  IF this works for PC and Mac:

                                  If(get(SystemPlatform = -2;

                                  Right(Substitute(get(DesktopPath) & "Folder/subFolder/;"/";"\\");Length(get(DesktopPath)& "Folder/subFolder/)-1;

                                  Length(get(DesktopPath)& "Folder/subFolder/)-1

                                  )

                                  Is there any difference from Mac for iPad, other than I would have to use 'get(Documents)' because there isn't a Desktop equivalent?

                                  • 14. Re: Exit script
                                    rouelf

                                    I know its has been answered; however, You my find the enclosed files useful and does not require plug-ins.  One file creates folders, the other file opens directories and specified folders; works in Windows and OS X. Scripts parameters are being used.

                                    1 of 1 people found this helpful
                                    1 2 Previous Next