1 2 Previous Next 16 Replies Latest reply on Jul 20, 2016 5:48 PM by itraining

    Create subfolder

    tays01s

      I create a folder using this 'Perform Applescript':

      "set theOutputFolderPath to path to " & If( $desktopFlag = 1; "desktop"; "documents") & " folder" & ¶ &

      "set theNewFolderName to " & Quote( $ns) & ¶ &

      "tell application \"Finder\" " &¶ &

      "if (exists folder (theOutputFolderPath & theNewFolderName as string)) = false then make new folder at theOutputFolderPath with properties {name:theNewFolderName} " & ¶ &

      "end tell"

      It works fine. However, when I have already created a subfolder (ns_ex) and run the following script again, it fails because it finds there's already a subfolder:

      "set theOutputFolderPath to (path to " & If( $desktopFlag = 1; "desktop"; "documents") & " folder as text) &" & Quote($ns) & ¶ &

      "set theNewFolderName to " & Quote($ns_ex) & ¶ &

      "tell application \"Finder\" " &¶ &

      "if (exists folder (theOutputFolderPath & theNewFolderName as string)) = false then make new folder at theOutputFolderPath with properties {name:theNewFolderName} " & ¶ &

      "end tell"

       

      Note the above subfolder script was adapted from a 'Soliant' script where the subfolder is a date/time, something that constantly changes and therefore simply creates a new subfolder without ever having a problem with the previously created subfolder name.

       

      Whilst I don't fully understand Applescript, I can't see why the subfolder command causes an 'Error message' whereas the folder command does not.

        • 1. Re: Create subfolder
          BruceRobertson

          It would be good if you would put together an example file.

          And of course, note that since finder item delimiters are colons, it seems likely that your timestamp could be a problem if it contains colons and they have not been substituted.

          • 2. Re: Create subfolder
            brucewilson

            "set theOutputFolderPath to (path to " & If( $desktopFlag = 1; "desktop"; "documents") & " folder as text) &" & Quote($ns) & ¶

             

            will not generate the correct path.

            try this

            "set theOutputFolderPath to (path to " & If( $desktopFlag = 1; "desktop"; "documents") & ":" & Quote($ns) & " folder as text)"  & ¶

             

             

            • 3. Re: Create subfolder
              tays01s

              brucewilson: Inserting ":" elicits an error specifying presence of ":".

               

              BruceRobertson: File attached. As mentioned, it correctly creates OSX folder + 2 subfolders in both Desktop and Documents, depending on Home::Folder_site setting. However, subsequent running of the script causes an error specifically concerning the subfolder creation, not the folder.

               

              NB.

              1. To test the Windows part of folder creation I have to create a Runtime. I must have an error(s) in that part of the script because although it runs without error messages, it does not create either a folder/subfolders on either Desktop or Documents.

              2. I'm trying to adapt other peoples' Applescript/ cmd.exe, so fully expect I'm likely to have made errors!!

              • 4. Re: Create subfolder
                monkeybreadsoftware

                If you use MBS Plugin and you want something cross platform, you may want to check Files.CreateDirectory function.

                (or use other plugin if you prefer)

                • 5. Re: Create subfolder
                  tays01s

                  I'd hoped to use the FM script alone so that it would also be potentially applied to an iPad/iPhone.

                  • 6. Re: Create subfolder
                    monkeybreadsoftware

                    The AppleScript will not work on iOS.

                    • 7. Re: Create subfolder
                      tays01s

                      Drat! That was a gem not mentioned when I was advised to put folders into Documents rather than Desktop.

                       

                      Slightly off my original Q, but how would you create a Folder/subFolder in iOS?

                       

                      Back to my original Q, why a repeat 'create folder' error for subfolders, not the folder?

                       

                      BruceRobertson: Time stamp?

                      • 8. Re: Create subfolder
                        brucewilson

                        iOS does not give you the option of creating folders, and anything that you output is pretty much sandboxed.

                         

                        I can't think of a good reason for a hosted solution to be saving multiple files on a local device.

                        If it was stand alone that makes more sense, but I still don't see what you would be doing with those files on iOS.

                        Can you tell us more about what you are doing?

                         

                        I have done the Applescript thing before, but I'm a little rusty.

                        I will have another go at it if you still can't get it working.

                        • 9. Re: Create subfolder
                          tays01s

                          Bruce, thanks.

                          Overview: I'm creating a standalone Runtime. The user needs to export some files. It seemed best to have an overall folder, inside which are 2 subfolders, 1 to export files to, 1 to import files from. The solution isn't at this stage worth the cost of hosting.

                           

                          iOS: I had read that you can't export/import records between devices. I got side-tracked into thinking I could.

                           

                          Applescript: I'm lost in knowing why errors occur when the script is run and there are already subfolders; the similar script for folder correctly avoids creation if there already is a folder.

                          • 10. Re: Create subfolder
                            BruceRobertson

                            "BruceRobertson: Time stamp?"

                             

                            See your original question.

                             

                            "adapted from a 'Soliant' script where the subfolder is a date/time"

                            • 11. Re: Create subfolder
                              user19752

                              1st script,

                              "set theOutputFolderPath to path to " & If( $desktopFlag = 1; "desktop"; "documents") & " folder"

                              then the value is "path to desktop folder". This is path.

                               

                              2nd script,

                              "set theOutputFolderPath to (path to " & If( $desktopFlag = 1; "desktop"; "documents") & " folder as text) &" & Quote($ns)

                              then the value is "(path to desktop folder as text) & someQuotedText". This is not a path, a text.

                              • 12. Re: Create subfolder
                                tays01s

                                BruceRobertson: TimeStamp, I see. Sorry, what I'd meant was that Soliant's example creates subfolders based on date/time, so because these constantly change, they are always new folders and therefore their script never has to detect subfolders of the same name and skip creating them. When I used a similar script that DID create subfolders of the same name, the script showed an error.

                                 

                                User19752: I assume '1st script' means my folder line? 2nd script subfolder? The problem is that I don't write Applescript, so I'm 'best guessing'. The original Soliant subfolder Applescript with my folder/subfolder substituted is:

                                "set theOutputFolderPath to path to " & If( $desktopFlag = 1; "desktop"; "documents") & $ns & "folder" & ¶ &

                                "set theNewFolderName to " & Quote($ns_ex) & ¶ &

                                "tell application \"Finder\" " &¶ &

                                "if (exists folder (theOutputFolderPath & theNewFolderName as string)) = false then make new folder at theOutputFolderPath with properties {name:theNewFolderName} " & ¶ &

                                "end tell"

                                 

                                but after creation of the subfolder, re-running the script triggers an error due to the subfolder already existing.

                                 

                                If you could give me a generic Applescript that solved this and/ or [some explanation of syntax], that would be a great help.

                                 

                                Thanks,

                                Stephen

                                • 13. Re: Create subfolder
                                  siplus

                                  your AppleScript will work whenever there's an application called "Finder" listening to your Applescript. Bad luck with iOS or with windows - kind of obvious.

                                   

                                  BE_CreateFolder – BaseElements Plugin Help Centre

                                  • 14. Re: Create subfolder
                                    BruceRobertson

                                    Here's my approach.

                                    1 2 Previous Next