9 Replies Latest reply on Aug 7, 2013 11:08 PM by grahamni

    Create folder on Mac from Dialog

    lkeyes

      Hi...seems like it should be easy...but ... I want to:

       

      1. Put up a custom dialog which asks for a folder name

      2. Create a folder with that name within the directory \users\lkeyes\documents\jobhunt

       

      Looked like this needs to happen with Applescript, but I guess I can't figure out how to pass the folder name from the custom dialog to the Applescript

       

      Right now there is a field in the record to hold the Foldername.... I don't really care if it is there; I'd rather just pass a variable...

       

       

       

      Show Custom Dialog [ Title: "Create New Job Folder"; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No”; Input #1:

      Job::FolderName, "Folder Name: " ]

       

      Commit Records/Requests

       

      Perform AppleScript [ Native AppleScript:

       

      --tell application "FileMaker Pro Advanced" set MyFolder to cell "FolderName" of current record
      --end tell

       

      tell application "Finder" activate

      make new folder at folder "JobHunt" of folder "Documents" of folder "lkeyes" of folder "Users" of startup disk with properties {name: MyFolder}
      end tell

      ]

       

      Right now this returns "Object Not Found" and Unknown Error -1728

        • 1. Re: Create folder on Mac from Dialog
          Mike_Mitchell

          You're probably better served with a plugin. There are several (Troi File and 360Works ScriptMaster are two that leap to mind immediately) that can accomplish this.

           

          Mike

          • 2. Re: Create folder on Mac from Dialog
            lkeyes

            Hi, Mike.... 

             

            I'd really like not to use a plug-in if I can get away with it. 

             

            I wouldn't rule it out of course.

             

            --- L

            • 3. Re: Create folder on Mac from Dialog
              s

              Hi L,

               

              Just a friendly reminder to search the list before posting:

              https://fmdev.filemaker.com/message/120185#120185

               

              Just add your Show Dialog step to capture the folder name from the user, and you should be able to make that work.

               

              You can also use Applescript to prompt the user to choose an existing folderr:

               

              set folderChoice to (choose folder)

              set folderChoiceString to (folderChoice as string)

              set cell "folder_path" of current record to folderChoiceString

               

              Note that you'll have to convert the applescript result because it uses this format:

              Macintosh HD:Users:steve:Desktop:my_folder:

               

              --

              Steve Moore

              Cumberland, Maine

              • 4. Re: Create folder on Mac from Dialog
                lkeyes

                Hi, Steve....here's what I finally came up with:

                 

                What I'm trying to do is simply create a folder in an existing subfolder:

                \Users\lkeyes\Documents\JobHunt\

                 

                 

                display dialog "Enter a folder name for your job:" default answer "" buttons {"OK", "Cancel"} default button 1

                copy the result as list to {text_returned, button_pressed}

                 

                 

                set p to path to documents folder as string

                set p to p & "Job Hunt:"

                 

                 

                tell application "Finder"

                          make new folder at p with properties {name:text_returned}

                end tell

                • 5. Re: Create folder on Mac from Dialog
                  anothersmurf

                  Applescript syntax is a pain. The easiest way is to use AppleSccript to call a shell script. Your AppleScript is:

                   

                  do shell script "mkdir \Users\lkeyes\Documents\JobHunt"

                   

                  When you calculate your script in FMP, you have to escape the quotes around the shell script:

                   

                  "do shell script \"mkdir " & $path_to_new_folder & "\""

                  • 6. Re: Create folder on Mac from Dialog
                    sporobolus

                    on 2013-08-02 13:09 s wrote

                    Just a friendly reminder to search the list before posting:

                      https://fmdev.filemaker.com/message/120185#120185#120185

                     

                    yeah, that thread is good, but i think lkeyes was almost there and is mainly

                    having syntax problems; "object not found" is because the name MyFolder is

                    undefined from AppleScript's perspective

                     

                    one thing i should have mentioned in my answer to that thread is that it's

                    pretty straightforward to use AppleScript without a call to the shell; the

                    following would work for the Perform AppleScript step in the OP's code; it

                    allows for spaces or other special characters in the folder name and covers for

                    the possibility that the folder already exists:

                     

                    "tell application \"Finder\"¶
                       if not (exists folder \"" & Job::FolderName & "\" of folder (path to 
                    documents folder)) then¶
                         make new folder with properties {name:\"" & Job::FolderName & "\"} at path 
                    to documents folder¶
                       end if¶
                    end tell"
                    

                     

                    if the folder name is in a variable, just use that in place of Job::FolderName

                    • 7. Re: Create folder on Mac from Dialog
                      Malcolm

                      I discovered that you can create folders using the "save as" dialog box on the Mac (at least). From the file menu select Save as PDF. In the file name field you can enter a file path including folder names by using the normal folder designator "/". Folders can be created to any depth. Windows users may want to try it with "\".

                       

                      Unfortunately, we cannot do it that easily from a script. The following throws an error.

                       

                      set variable [$file ; get(desktoppath) & "test/abc.pdf"]

                      save as pdf[$file]

                       

                      malcolm

                      • 8. Re: Create folder on Mac from Dialog

                        The answer really depends on who has planned access to this dialog, along with what it will be used for.

                         

                        display dialog "Enter a folder name for your job:" default answer "" buttons {"OK", "Cancel"} default button 1

                        copy the result as list to {text_returned, button_pressed}

                        For the script in your last post, you should change the user input to a loop, preventing a string with nothing:

                         

                        set the_folder to ""

                        repeat until the_folder ≠ ""

                                  set the_folder to text returned of (display dialog "Enter a folder name for your job:" default answer "" buttons {"OK", "Cancel"} default button 1)

                        end repeat

                         

                         

                        If a text box is not required, then maybe use the "choose folder" command:

                         

                        set the_folder to choose folder

                         

                        You can even require the folder to be within a subfolder with this loop:

                         

                        set the_folder to ""

                        repeat until (the_folder as string) contains (path to documents folder as string)

                                  set the_folder to choose folder

                                  if (the_folder as string) does not contain (path to documents folder as string) then

                                            display dialog "The folder must be inside the Documents folder."

                                  end if

                        end repeat

                        • 9. Re: Create folder on Mac from Dialog

                          Shell scripts are great, I use them a lot, but if you can't trust the user then always filter the variable before it goes in into the script. If you don't, the user is just one " | " away from running his/her own shell scripts.