6 Replies Latest reply on Sep 24, 2013 9:01 AM by fourier48

    Opening a Mac OS X folder via a FMP script

    KylePutzier

      I would like to open a folder on an OS X computer that "starts" with a word (a number actually) that FMP supplies via a script. I'm not talking about opening a dialog to a particular folder. I need to actually display the folders contents on from the OS X desktop. All folders would be contained in a known parent folder.

       

      Can someone point me in the right direction.

      Applescript is fine, although I'm not proficient using applescript. Plugins are fine also.

       

      Kyle

        • 1. Re: Opening a Mac OS X folder via a FMP script
          sporobolus

          on 2013-09-19 10:58 KylePutzier wrote

          I would like to open a folder on an OS X computer that "starts" with a word (a number actually) that FMP supplies via a script. I'm not talking about opening a dialog to a particular folder. I need to actually display the folders contents on from the OS X desktop. All folders would be contained in a known parent folder.

           

          Can someone point me in the right direction.

          Applescript is fine, although I'm not proficient using applescript.  Plugins are fine also.

           

          assuming you set script variables $parent_folder (HFS-style path) and

          $starts_with, the following calculated AppleScript will do it:

           

          "set parent_folder to \"" & $parent_folder & "\"¶
          set prefix to \"" & $starts_with & "\"¶
          tell application \"Finder\"¶
             set folder_names to name of every folder of folder parent_folder¶
             repeat with f in folder_names¶
               if first word of f is prefix then¶
                 open folder f of folder parent_folder¶
                 activate¶
                 exit repeat¶
               end if¶
             end repeat¶
          end tell"
          

           

          if you're not comfortable with HFS path syntax, and/or if this is to be used on

          multiple machines, it may be easier to specify the parent folder relative to

          something like the user's Documents or Desktop folder:

           

          "set parent_folder to ((path to documents folder) as text) & \"" & 
          $parent_folder & "\"¶
          

           

          • 2. Re: Opening a Mac OS X folder via a FMP script
            KylePutzier

            Thank you Steve,

             

            I wasn't able to make it work exactly like your example, but I did eventually muddle through it and got something that works. I couldn't get the $parent_folder to work, so I just hard coded it.

             

            "tell application \"Finder\"¶

                      set folder_names to name of every folder of folder (\"/Users/kyleputzier/Desktop/BackMeUp/Current Art\" as POSIX file)¶

                      repeat with f in folder_names¶

                                if first word of f is \"" & $starts_with & "\" then¶

                                          open folder f of folder (\"/Users/kyleputzier/Desktop/BackMeUp/Current Art\"as POSIX file)¶

                                          activate¶

                                          exit repeat¶

                                end if¶

                      end repeat¶

            end tell¶"

             

            Now what I would like to do is have it give me the option of creating a new folder if the searched for folder doesn't exist.

            eg.: 1501 MyFolderName

             

            and have 2 subfolders inside that:

            ~ Original Art

            ~ Obsolete

             

            Could you please help me just a wee bit more?

            • 3. Re: Opening a Mac OS X folder via a FMP script
              dwelam

              Productive Computing makes a nice plugin called File Manipulator that will do what you are looking for.

              • 4. Re: Opening a Mac OS X folder via a FMP script
                KylePutzier

                Nevermind. I figured it out

                 

                 

                "

                tell application \"Finder\"¶

                          set folder_names to name of every folder of folder (\"/Users/kyleputzier/Desktop/BackMeUp/Current Art\" as POSIX file)¶

                          repeat with f in folder_names¶

                                    if first word of f is \"" & _Company Items::ID_CompanyItem & "\" then¶

                                              open folder f of folder (\"/Users/kyleputzier/Desktop/BackMeUp/Current Art\" as POSIX file)¶

                                              activate¶

                                              set Found to 1¶

                                              exit repeat¶

                                    else¶

                                              set Found to 0¶

                                    end if¶

                          end repeat¶

                          if Found = 0 then¶

                                    open folder  (\"/Users/kyleputzier/Desktop/BackMeUp/Current Art\" as POSIX file)¶

                                    set question to display dialog \"The art folder could not be found. Would you like to create one?\" buttons {\"Yes\", \"No\"} default button 2¶

                                    set answer to button returned of question¶

                 

                                    if answer is equal to \"Yes\" then¶

                                              set newfoldername to \"" & _Company Items::ID_CompanyItem & " " & _Company Items::Graphics_FilenameSuffix & "\"¶

                                              set loc to (\"/Users/kyleputzier/Desktop/BackMeUp/Current Art\" as POSIX file)¶

                                              set newfo to make new folder at loc with properties {name:newfoldername}¶

                                              make new folder at newfo with properties {name:\"~ Obsolete\"}¶

                                              make new folder at newfo with properties {name:\"~ Original Art\"}¶

                                              open folder newfoldername of folder (\"/Users/kyleputzier/Desktop/BackMeUp/Current Art\" as POSIX file)¶

                                    end if¶

                          end if¶

                end tell¶

                "

                • 5. Re: Opening a Mac OS X folder via a FMP script
                  sporobolus

                  on 2013-09-20 8:59 KylePutzier wrote

                  Now what I would like to do is create a new folder if the searched for folder doesn't exist.

                  eg.: 1501 MyFolderName

                   

                  and have 2 subfolders inside that:

                  ~ Original Art

                  ~ Obsolete

                   

                  Could you please help me just a wee bit more?

                   

                  your later messsage says you "figured it out" … assuming that you sorted out

                  the use of the script variables, this modifies my example to create the folders

                  you describe when the folder doesn't already exist

                   

                  "set parent_folder to \"" & $parent_folder & "\"¶
                  set prefix to \"" & $starts_with & "\"¶
                  tell application \"Finder\"¶
                     set folder_names to name of every folder of folder parent_folder¶
                     set found_folder to false¶
                     repeat with f in folder_names¶
                       if first word of f is prefix then¶
                         open folder f of folder parent_folder¶
                         activate¶
                         set found_folder to true¶
                         exit repeat¶
                       end if¶
                     end repeat¶
                     if not found_folder then¶
                       set new_folder to make new folder in folder parent_folder with properties 
                  {name:prefix & \" myFolderName\"}¶
                       make new folder in new_folder with properties {name:\"~ Original Art\"}¶
                       make new folder in new_folder with properties {name:\"~ Obsolete\"}¶
                       open new_folder¶
                       activate¶
                     end if¶
                  end tell¶
                  ¶
                  "
                  

                   

                  • 6. Re: Opening a Mac OS X folder via a FMP script
                    fourier48

                    ... and Base Elements :-)