9 Replies Latest reply on Jul 7, 2012 1:46 PM by EddieAlbert

    Script to open folder in OSX



      Script to open folder in OSX


      I know absolutely nothing about applescript or scripting in general for that matter. I'd like to set up a button in filemaker that will open a folder in OSX. The folder is on a PC server but can be mounted as a volume in the finder. The folder names correspond to a file id number in a filemaker database. What i'd like the button to do is get the value of the file id number in the current table and pass that value to an applescript that will open the folder with that id number. I hope that makes sense. I've been playing around with some scripting ive found on the internet. I've got the script in two parts basically.

      This part of the script gets the file id number from the first record in the table. What i need is for it to get the value of the current record.
      tell application "FileMaker Pro Advanced"
      tell database "ordertracker"
      tell table "mylars"
      cell "mylarID"
      end tell
      end tell
      end tell

      This part of the script opens the folder but what i need is for the number "067" to be the variable retrieved from the first step.

      tell application "Finder"
      set my_folder to "CP-Mylars:067:web Layout & 1up:"
      open folder my_folder
      end tell

      Also, is there a way to make this work if the volume is not currently mounted?

      Any help would be greatly appreciated.

        • 1. Re: Script to open folder in OSX

          Google "applescript open folder"

          Link #3 may be useful - posting to an Applescript specific forum may get a better response.

          • 2. Re: Script to open folder in OSX

            I tried that. The applescript part of opening the folder seems pretty straightforward. The only problem i'm having is getting the field name in filemaker to act as a variable in applescript for the folder name.

            • 3. Re: Script to open folder in OSX

              Is there no way to pass data from a field in filemaker to applescript? I know how to make applescript open a folder to me if i know the path. The problem is i need to know how to turn a field value into an applescript variable.

              I've gotten a little closer. The script below gives me the value i need. In the next script i need to replace the number "067" with the result of the first script. Is there any way to do that? Also, like i said, i'm very new to this. i'm sure there is a way to condense the two scripts into one. I'm open to suggestions.

              tell application "FileMaker Pro Advanced"
              cell "mylarID" of current record
              end tell

              tell application "Finder"
              open folder "CP-Mylars:067:"
              end tell


              • 4. Re: Script to open folder in OSX

                Is this not possible?

                • 5. Re: Script to open folder in OSX

                  "Open url"might help as it supports httpftpfile, and mailto URL types:



                  It doesn't mention folders, though. 


                  I'm a rank novice, who would like to also open a set of related files in a folder from Filemaker, so, assuming you figure it out, let us know how.


                  Good luck!


                  • 6. Re: Script to open folder in OSX

                    On Windows, Open URL does the job perfectly.  You can capture the ID as a $Variable and set the path name using it.

                    • 7. Re: Script to open folder in OSX

                      @Pete Schlosser,

                      I believe that what you want can be done in AppleScript as I've seen any number of apple script examples that use data from FileMaker, but I'm not aware of any current Forum participants, including myself, that are fluent in Applescript. You may need to research this one on an Applescripting site or a different FileMaker forum.

                      • 8. Re: Script to open folder in OSX

                        Pate - why does Open URL not work for you?

                        • 9. Re: Script to open folder in OSX

                          To get data from filemaker into an applescript, you have to use applescript to grab the data.
                          That is what is happening in the tell me statement below
                          The Job number is grabbed from the current record and saved into a variable.


                          This script gets job number from the database named "JSR9",
                          It then gets the last digit of the Job Number and determines if it is an even number or odd number
                          Even numbered jobs are stored on a volume named AraxiVolume_2B
                          Odd numbered jobs are stored on a volume named AraxiVolume_1A

                          so a variable named RaidVolume is set based on the last digit of the job number (even # or odd)

                          Then we tell the finder what to do


                          So, if the job number was 45678, this is what is opened:    AraxiVolume_2B/Jobs/45678_CustomerName/UserDefinedFolders/
                          I did it that way because we dont put the customer name in the database in the same way we name the folders.
                          Thus I have the script open "every folder whose name begins with JobNo"

                          But you can alter the script to open a specific folder if that is a known entity.
                          If you do that, the script will run MUCH faster
                          My way is slow because applescript has to look at EVERY folder on the volume and see which ones start with the job number


                          -- ==================
                          -- START SCRIPT
                          -- ==================

                          tell me
                                   tell database "JSR9"
                                  tell current record
                                      set JobNo to cell "JobNo" as string
                                  end tell
                              end tell
                          end tell

                          set LastDigit to last character of JobNo
                          set LastDigit_div2 to LastDigit / 2
                          set LastDigit_rounded to round LastDigit_div2

                          if LastDigit_rounded = LastDigit_div2 then
                              set RaidVolume to "AraxiVolume_2B:Jobs"
                              set FolderPath to alias "AraxiVolume_2B:Jobs:"
                              set RaidVolume to "AraxiVolume_1A:Jobs"
                              set FolderPath to alias "AraxiVolume_1A:Jobs:"
                          end if

                          tell application "Finder"
                                  --open folder RaidVolume
                                  set x to (every folder whose name begins with JobNo) of FolderPath
                                  set TheFolder to item 1 of x
                                  --    open TheFolder
                                  open folder "UserDefinedFolders" of TheFolder
                              end try
                          end tell


                          -- ==================
                          -- END SCRIPT
                          -- ==================