9 Replies Latest reply on Jun 18, 2013 8:09 AM by willrollo

    Cross platform script

      Title

      Cross platform script

      Post

           Hi

           I currently run a script on a mac system that creates a folder automatically on the desktop of a users computer. The folder's name is set by a field from the record that is being created - in this case, Name_short reversed (ie Smith, John)

           However, I plan on running FM12 on a mac server. I am not sure how to alter the script so that those connected to it can create this folder on the server as opposed to the user's own machine.

           The second question I have, is that if a PC is using this new script, then will it still work when creating this folder on the mac server?

           Thank you

            

             
      •           Set Error Capture [ On ]
      •      
      •           If [ Customers::Folder Created = "No" ]
      •      
      •           Perform AppleScript [ Native AppleScript: --tell application "FileMaker Pro Advanced" set folder_name to cell "Name_ShortReversed" of current record --end tell set DT to path to desktop tell application "Finder" try make new folder at "Macintosh HD:Users:williamrollo:Desktop:Enquiries:" with properties {name:folder_name} end try end tell ]
      •      
      •           If [ Get(LastError) ≠ 0 ]
      •      
      •           #Test PDF creation and save
      •      
      •           Show Custom Dialog [ Title: "Warning"; Message: "There was a problem creating the folder"; Default Button: “OK”, Commit: “Yes” ]
      •      
      •           Exit Script [ ]
      •      
      •           End If
      •      
      •           Set Field [ Customers::Folder Created; "Yes" ]
      •      
      •           Show Custom Dialog [ Title: "Information"; Message: "Folder Created"; Default Button: “OK”, Commit: “Yes” ]
      •      
      •           End If

        • 1. Re: Cross platform script
          philmodjunk

               You normally would not create the directory for each such client system, you'd create it once and then each client system would map/mount the shared directory.

               You cannot perform an AppleScript from Windows systems. But you can mount/map to a shared directory using a batch or VBScript file. Your system can use a get function to identify which system just opened the database and it can then either perform the AppleScript or the Batch/VBScript to mount/map to the shared directory.

               And please keep in mind that the fact that windows systems use a drive letter and Mac systems use a volumne name means that the resulting file path to the shared directory will be different for your two systems and this will typically require additional work on your part to get this working cross platform.

          • 2. Re: Cross platform script

                 Hi Phil

                 Yes, I was aware of the second point you raised (different paths for differents OS) - however, I have no experience on PC VB programming! But I would like to get the first issue working first, which is to be able to create a folder on a mac server from a mac client - You can see from my script that the client checks the folder has not already been created before executing the script. The folder is created so that when quotes/invoices etc are rpimted, copies (pdf) are exported into these folders...I have all this working but only on the client mac that I have been designing the DB on - cant seem to get it to create folder remotely over my network to the mac server - Is it that the path maybe wrong or something more comlicated?

                  

                 Thank you!

            • 3. Re: Cross platform script

                   Have sorted it - finally. Below is my basic applescript which I have bolted on to my fm script so that the new folder is named by a field from the current record..

                   tell application "Finder"
                       
                       mount volume "afp://Macbook Air._afpovertcp._tcp.local/Macintosh HD/Users/myserver/Documents/" as user name "myserver" with password "password"
                       
                   end tell

                   tell application "Finder"
                       make new folder at alias "Volumes:Macintosh HD-1:Users:myserver:Documents" with properties {name:"my folder"}
                   end tell
                    

              • 4. Re: Cross platform script
                JimMac

                     Ok , so far so good.yes  What happens if the Folder already exists?

                     And...

                     Who purges the Server folder?

                     What is the Maximum Files size allowed on the Server?

                     Does the Server slow down when a Client is Saving  a large PDF?

                     Jim...

                • 5. Re: Cross platform script

                       Jim...

                       Answers Below:

                       What happens if the Folder already exists? - I have set the name of the folder to be a calc field that contains the surname followed by unique ID number. SO this shouldnt happen - Once a folder has been created for that reocrd, another field is set to a 1  - By default is is a 0 whcih is checked on execution of the new folder script - does that make sense?

                       And...

                       Who purges the Server folder? - if anyone, me - but this shouldnt be neccessary

                       What is the Maximum Files size allowed on the Server? No limit as yet

                       Does the Server slow down when a Client is Saving  a large PDF? - untested but doubt it

                        

                       The reason the folders are to be created is to hold pdf copies of any quotes or invoices sent out to the client (We sell unqique besoke furniture, so not many per client) and also photos of these pieces where neccessary - so only a few photos maybe in each folder. So I dont think too many limitations or controls are required - and there will only be three users connected to server at any one time!

                       I hope that answers your query - Thank you for bringing those to my attention though as hadnt thought much about things like that - I have been concentrating so much on getting the script to work!

                  • 6. Re: Cross platform script
                    JimMac

                         Thanks for the response.  I was headed in a similar direction so I am not second guessing you.angel

                         It appears  the Folders are unique and primary for internal use and "freezing" a quote, etc.

                         i am setting up an external FMP file for the "copies" with a table that uses probably your ClientID as a Foreign Key... in my case it is a real estate PropertyID and a Container that "embeds" the stored Document [copy].

                         I will save that External file to a new "Thunderbolt" Hard Drive of 3 TB size directly connected to my Mac Server computer.  In my case, I dont need a folder, my New drive is the FOLDERwink.  No need to calculate a name, the Relationship "tags" it.

                         By doing it this way, when i delete a Property from lack of use or record keeping time limit, the embedded copies go bye bye too.yes

                         Thunderbolt is the new Ultra high speed USB type data port.  USB x 100surprise.

                         Jim...

                    • 7. Re: Cross platform script

                           Hi Jim

                           As mentioned I have managed to create new dynamic folders on the server. However, trying to export PDFs with dynamic names to the server appears a little more tricky. so I have thought about doing this whole export pdf feature on a dropbox account that will be on all the macs anyway. However, there is obviously a problem doing this as all paths from each mac will be different unless I set them all up with the same user name! Any ideas on how to get aorund this? I thought of maybe adding an if and variable filepaths based on the user but wondered if there may be a better idea...

                           Below are my two current scripts - one for creating a folder on the server, the other for exporting a quote to the dropbox on a local computer as unable to export to server when using a dynamically created folder name  - does this make sense?

                            

                           New folder named after the field "folder_name"

                             
                      •           Set Error Capture [ On ]
                      •      
                      •           If [ Customers::Folder Created = "No" ]
                      •      
                      •           Perform AppleScript [ Native AppleScript: --tell application "FileMaker Pro Advanced" set folder_name to cell "Folder Name" of current record --end tell tell application "Finder" mount volume "afp://Macbook Air._afpovertcp._tcp.local/Macintosh HD/Users/server/Documents/" as user name "server" with password "password" end tell tell application "Finder" make new folder at alias "Volumes:Macintosh HD-1:Users:server:Documents" with properties {name:folder_name} end tell ]
                      •      
                      •           If [ Get(LastError) ≠ 0 ]
                      •      
                      •           #Test PDF creation and save
                      •      
                      •           Show Custom Dialog [ Title: "Warning"; Message: "There was a problem creating the folder"; Default Button: “OK”, Commit: “Yes” ]
                      •      
                      •           Exit Script [ ]
                      •      
                      •           End If
                      •      
                      •           Set Field [ Customers::Folder Created; "Yes" ]
                      •      
                      •           Show Custom Dialog [ Title: "Information"; Message: "Folder Created"; Default Button: “OK”, Commit: “Yes” ]
                      •      
                      •           End If

                           Export quote - Exported to Dropbox folder on my mac but this obviously will not work on other macs. It is saved as the quote number followed by the reference.pdf. I tried this addition below to try to add it to the dynamic folder (Script above not targeted to dropbox as yet but for this addition it wil need to be altered - would rather get the server option working as opposed to the dropbox version.)

                      "filemac:/Macintosh HD/Users/williamrollo/Dropbox/ & invoicedetails_CUSTOMERS__billing::Folder Name "

                             
                      •           Allow User Abort [ Off ]
                      •      
                      •           Set Error Capture [ On ]
                      •      
                      •           If [ Get(WindowMode) = 0 ]
                      •      
                      •           If [ Get(ScriptParameter) = "Quote" ]
                      •      
                      •           Commit Records/Requests [ Skip data entry validation; No dialog ]
                      •      
                      •           Freeze Window
                      •      
                      •           If [ Count(invoicedetails_INVOICEITEM::ID_InvoiceLI_pk) ]
                      •      
                      •           #Test for line items
                      •      
                      •           Go to Related Record [ From table: “invoicedetails_INVOICEITEM”; Using layout: “Quote Print” (INVOICEITEMS) ] [ Show only related records; New window ]
                      •      
                      •           View As [ View as List ]
                      •      
                      •           Else
                      •      
                      •           Show Custom Dialog [ Title: "Warning"; Message: "There are no line items on this quote."; Default Button: “OK”, Commit: “Yes” ]
                      •      
                      •           Exit Script [ ]
                      •      
                      •           End If
                      •      
                      •           Enter Preview Mode
                      •      
                      •           Show/Hide Toolbars [ Show ]
                      •      
                      •           Adjust Window [ Resize to Fit ]
                      •      
                      •           Go to Record/Request/Page [ Last ]
                      •      
                      •           Set Field [ PREF::gPageNumber; Get(PageNumber) ]
                      •      
                      •           Go to Record/Request/Page [ First ]
                      •      
                      •           Set Variable [ $Path; Value:"filemac:/Macintosh HD/Users/williamrollo/Dropbox/ " & Invoiceitems_INVOICEDETAILS::fk_Quote & " " & Invoiceitems_INVOICEDETAILS::Reference & ".PDF" ]
                      •      
                      •           Save Records as PDF [ File Name: “$Path”; Records being browsed ] [ Document - Title: INVOICE DETAILS::fk_Quote; Compatibility: Acrobat 5 and later ] [ Pages - Number Pages From: 1; Include: All pages ] [ Security - Printing: High Resolution; Editing: Any except extracting pages; Enable copying; Enable Screen Reader ] [ Initial View - Show: Pages Panel and Page; Page Layout: Single Page; Magnification: 100% ] [ Restore; No dialog ]
                      •      
                      •           If [ Get(LastError) ≠ 0 ]
                      •      
                      •           #Test PDF creation and save
                      •      
                      •           Show Custom Dialog [ Title: "Warning"; Message: "There was a problem creating the PDF, Email cancelled."; Default Button: “OK”, Commit: “Yes” ]
                      •      
                      •           Exit Script [ ]
                      •      
                      •           End If
                      •      
                      •           Close Window [ Current Window ]

                            

                      • 8. Re: Cross platform script
                        JimMac

                             FMP does't provide a rich set of OS file folder/document commands.  Thats is why MacOS users like Applescriptsyes.  I thought about ways to avoid the folder creation and use the OS list files by... Name so that all "clients" would be grouped by a combination of Name|ID|date.  That is a similar thought to DropBox use.  My worry was a "ever increasing" files storage that would quickly becomes a undecipherable mess that someone would eventually have to backup/delete/retrievecrying.

                             Ahhh hahhhh.... Container Fields with External Reference in FMP12enlightened  In FMP12 Help About setting up container fields lists all the good reasons to store PDF etc. in exteranal references relative to the Server for multi-client use.  So I was proceeding down that path to store copies of PDF's that would be a snapshot of Time Sensitive Documents [ like your quotes ]

                             But...

                             I don't think that when I delete the Container Record with an Exteral File Reference, that the external referenced file is ALSO deleted [untested by me so far].

                             However an Embedded File would be deleted.smiley.  Therefore my "housekeeping" problem solved and the file/folder naming not needed.yes

                             Ouch.. but what about the slow down of larged embedded files within the Main Records and that File getting bloated in size, which may required a few hours to back up and minutes to sort.

                             Since the PDF etc. files are "copies" of a paper file, their use is limited to infequent access.

                             So...

                             Create an External FMP file with a Table of Containers that are Related to the ClientID, with the embedded documents in a Container, Descriptions, TimeStamped, etc. for sorting and retriveal.  Save that related FMP file on an external high speed drive, file path relative to the Server and available to all Clients, when rarely needed.  Using an External Drive allows dynamic back ups of that drive without slowing down the Server.

                             Thus we now how a digital copy of our paper files.yes

                             I welcome suggestions for other methods.  I was hoping you had solved the File/Folder naming and file references but it seems you are running into problems.

                             Jim...

                        • 9. Re: Cross platform script

                               Thank you Jim

                               I think I shall take a moment to digest it all!