MBS FileMaker Plugin Example Databases

FileOperation

All examples are included with download of MBS FileMaker Plugin.

FileOperation.fmp12

Overview
Tables1
Relationships0
Layouts1
Scripts5
Value Lists0
Custom Functions0
Custom Menus33
File Options
Default custom menu set[Standard FileMaker Menus]
When opening file
Minimum allowed version12.0
Login usingAccount Name; Account= Admin
Allow user to save passwordOff
Require iOS passcodeOff
Switch to layoutOff
Hide all toolbarsOff
Script triggers
OnFirstWindowOpenOff
OnLastWindowCloseOff
OnWindowOpenOff
OnWindowCloseOff
OnFileAVPlayerChangeOff
Thumbnail Settings
Generate ThumbnailsOn; Temporary

 

Tables

Table Name
Statistics
Occurrences in Relationship Graph
FileOperation
3 fields defined, 1 record
FileOperation

Fields

Table Name: FileOperation - 3 Fields
Field NameTypeOptionsCommentsOn LayoutsIn RelationshipsIn ScriptsIn Value Lists
SourcePathNormal, TextAuto-Enter:
  • Allow editing
Validation:
  • Only during data entry
Storage:
  • Repetitions: 1
  • Indexing: None
  • Automatically create indexes as needed
  • Index Language: German
      DestinationPathNormal, TextAuto-Enter:
      • Allow editing
      Validation:
      • Only during data entry
      Storage:
      • Repetitions: 1
      • Indexing: None
      • Automatically create indexes as needed
      • Index Language: German
          ResultNormal, TextAuto-Enter:
          • Allow editing
          Validation:
          • Only during data entry
          Storage:
          • Repetitions: 1
          • Indexing: None
          • Automatically create indexes as needed
          • Index Language: German

              Layout Objects: FileOperation

              Regular Fields

              Field Name: FileOperation::SourcePath
              Field PropertiesCoordinatesField FormatField BehaviorQuick Find
              • Top: 8 pt
              • Left: 157 pt
              • Bottom: 27 pt
              • Right: 410 pt
              • Anchoring: Left and Right, Top
              Field Format:
              • Edit Box
              Field Behavior:
              • Allow field to be entered: In Find mode, In Browse mode
              • Touch keyboard type: Default for Data Type
              • Go to next field using: Tab key
              Yes

              Field Name: FileOperation::DestinationPath
              Field PropertiesCoordinatesField FormatField BehaviorQuick Find
              • Top: 31 pt
              • Left: 157 pt
              • Bottom: 50 pt
              • Right: 410 pt
              • Anchoring: Left and Right, Top
              Field Format:
              • Edit Box
              Field Behavior:
              • Allow field to be entered: In Find mode, In Browse mode
              • Touch keyboard type: Default for Data Type
              • Go to next field using: Tab key
              Yes

              Field Name: FileOperation::Result
              Field PropertiesCoordinatesField FormatField BehaviorQuick Find
              • Top: 54 pt
              • Left: 157 pt
              • Bottom: 73 pt
              • Right: 410 pt
              • Anchoring: Left and Right, Top
              Field Format:
              • Edit Box
              Field Behavior:
              • Allow field to be entered: In Find mode, In Browse mode
              • Touch keyboard type: Default for Data Type
              • Go to next field using: Tab key
              Yes

              Buttons

              Button PropertiesCoordinatesScript/Script Step
                Type:
              • Text: Move to Trash
              • Top: 87 pt
              • Left: 40 pt
              • Bottom: 114 pt
              • Right: 200 pt
              • Anchoring: Left, Top
              Perform Script [ “Move To Trash” ]

              Scripts:


              Button PropertiesCoordinatesScript/Script Step
                Type:
              • Text: Copy File/Folder
              • Top: 87 pt
              • Left: 250 pt
              • Bottom: 114 pt
              • Right: 410 pt
              • Anchoring: Left, Top
              Perform Script [ “Copy File” ]

              Scripts:


              Button PropertiesCoordinatesScript/Script Step
                Type:
              • Text: Move File/Folder
              • Top: 128 pt
              • Left: 40 pt
              • Bottom: 155 pt
              • Right: 200 pt
              • Anchoring: Left, Top
              Perform Script [ “Move File” ]

              Scripts:


              Button PropertiesCoordinatesScript/Script Step
                Type:
              • Text: Copy Folder recursively
              • Top: 128 pt
              • Left: 250 pt
              • Bottom: 155 pt
              • Right: 410 pt
              • Anchoring: Left, Top
              Perform Script [ “CopyFolder” ]

              Scripts:


              Script Hierarchy

              Move File
              Copy File
              Move To Trash
              CopyFolder Recursive
              CopyFolder

              Next Script: [Copy File]
              Script NameMove File
              Run script with full access privilegesOff
              Include In MenuYes
              Layouts that use this script
              Scripts that use this script
                Script Definition
                Script Steps
                • Set Variable [ $result; Value:MBS("Files.MoveFile"; FileOperation::SourcePath; FileOperation::DestinationPath) ]
                • Set Field [ FileOperation::Result; $result ]
                Fields used in this script
                Scripts used in this script
                  Layouts used in this script
                    Tables used in this script
                    Table occurrences used by this script
                    Custom Functions used by this script
                      Custom menu set used by this script

                        Previous Script: [Move File]Next Script: [Move To Trash]
                        Script NameCopy File
                        Run script with full access privilegesOff
                        Include In MenuYes
                        Layouts that use this script
                        Scripts that use this script
                          Script Definition
                          Script Steps
                          • Set Variable [ $result; Value:MBS("Files.CopyFile"; FileOperation::SourcePath; FileOperation::DestinationPath) ]
                          • Set Field [ FileOperation::Result; $result ]
                          Fields used in this script
                          Scripts used in this script
                            Layouts used in this script
                              Tables used in this script
                              Table occurrences used by this script
                              Custom Functions used by this script
                                Custom menu set used by this script

                                  Previous Script: [Copy File]Next Script: [CopyFolder Recursive]
                                  Script NameMove To Trash
                                  Run script with full access privilegesOff
                                  Include In MenuYes
                                  Layouts that use this script
                                  Scripts that use this script
                                    Script Definition
                                    Script Steps
                                    • Set Variable [ $result; Value:MBS("Files.MoveToTrash"; FileOperation::SourcePath) ]
                                    • Set Field [ FileOperation::Result; $result ]
                                    Fields used in this script
                                    Scripts used in this script
                                      Layouts used in this script
                                        Tables used in this script
                                        Table occurrences used by this script
                                        Custom Functions used by this script
                                          Custom menu set used by this script

                                            Previous Script: [Move To Trash]Next Script: [CopyFolder]
                                            Script NameCopyFolder Recursive
                                            Run script with full access privilegesOff
                                            Include In MenuNo
                                            Layouts that use this script
                                              Scripts that use this script
                                              Script Definition
                                              Script Steps
                                              • Set Variable [ $json; Value:Get(ScriptParameter) ]
                                              • #query the input and output paths we got
                                              • Set Variable [ $SourcePath; Value:MBS( "JSON.GetPathItem"; $json; "SourcePath"; 3) ]
                                              • Set Variable [ $DestPath; Value:MBS( "JSON.GetPathItem"; $json; "DestPath"; 3) ]
                                              • Set Variable [ $Recursion; Value:MBS( "JSON.GetPathItem"; $json; "Recursion"; 3) ]
                                              • If [ IsEmpty($Recursion) ]
                                              • #called by user, so check input
                                              • #check source
                                              • Set Variable [ $r; Value:MBS( "Files.DirectoryExists"; $SourcePath ) ]
                                              • If [ $r ≠ 1 ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "Error"; "Invalid source path") ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "ErrorDetail"; $r) ]
                                              • Exit Script [ Result: $json ]
                                              • End If
                                              • #check dest. Create as folder. If already exists, this will not be an error
                                              • Set Variable [ $r; Value:MBS( "Files.CreateDirectory"; $DestPath ) ]
                                              • If [ MBS("IsError") ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "Error"; "Failed to create directory: " & $DestPath) ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "ErrorDetail"; $r) ]
                                              • Exit Script [ Result: $json ]
                                              • End If
                                              • Set Variable [ $r; Value:MBS( "Files.DirectoryExists"; $DestPath) ]
                                              • If [ $r ≠ 1 ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "Error"; "Invalid destination path") ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "ErrorDetail"; $r) ]
                                              • Exit Script [ Result: $json ]
                                              • End If
                                              • End If
                                              • #get directory listing
                                              • Set Variable [ $list; Value:MBS("Files.List"; $SourcePath) ]
                                              • If [ MBS("IsError") ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "Error"; "Failed to get directory listing") ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "ErrorDetail"; $list) ]
                                              • Exit Script [ Result: $json ]
                                              • End If
                                              • #loop counting up from 1 to $count
                                              • Set Variable [ $count; Value:ValueCount ( $list ) ]
                                              • Set Variable [ $index; Value:1 ]
                                              • If [ $index ≤ $count ]
                                              • Loop
                                              • #your script steps here
                                              • Set Variable [ $ItemName; Value:GetValue($list; $index) ]
                                              • Set Variable [ $ItemPath; Value:MBS( "Path.AddPathComponent"; $SourcePath; $ItemName ) ]
                                              • Set Variable [ $ItemDest; Value:MBS( "Path.AddPathComponent"; $DestPath; $ItemName ) ]
                                              • If [ MBS( "Files.DirectoryExists"; $ItemPath ) ]
                                              • #copy folder with recursion
                                              • #create new folder
                                              • Set Variable [ $r; Value:MBS( "Files.CreateDirectory"; $ItemDest ) ]
                                              • If [ MBS("IsError") ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "Error"; "Failed to create directory: " & $ItemDest) ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "ErrorDetail"; $r) ]
                                              • Exit Script [ Result: $json ]
                                              • End If
                                              • #prepare JSON for recursive call
                                              • Set Variable [ $jsonCall; Value:"{}" ]
                                              • Set Variable [ $jsonCall; Value:MBS( "JSON.SetPathItem"; $jsonCall; "SourcePath"; MBS( "JSON.CreateString"; $ItemPath)) ]
                                              • Set Variable [ $jsonCall; Value:MBS( "JSON.SetPathItem"; $jsonCall; "DestPath"; MBS( "JSON.CreateString"; $ItemDest)) ]
                                              • Set Variable [ $jsonCall; Value:MBS( "JSON.SetPathItem"; $jsonCall; "Recursion"; "true") ]
                                              • Perform Script [ “CopyFolder Recursive”; Parameter: $jsonCall ]
                                              • Set Variable [ $jsonResult; Value:Get(ScriptResult) ]
                                              • #check error
                                              • Set Variable [ $Error; Value:MBS( "JSON.GetPathItem"; $jsonResult; "Error"; 3 ) ]
                                              • If [ Length ( $Error ) > 0 ]
                                              • #pass back
                                              • Exit Script [ Result: $jsonResult ]
                                              • End If
                                              • #handle statistics
                                              • Set Variable [ $FilesCopied1; Value:MBS( "JSON.GetPathItem"; $json; "FilesCopied"; 3 ) ]
                                              • Set Variable [ $FilesCopied2; Value:MBS( "JSON.GetPathItem"; $jsonResult; "FilesCopied"; 3 ) ]
                                              • Set Variable [ $json; Value:MBS( "JSON.SetPathItem"; $json; "FilesCopied"; $FilesCopied1 + $FilesCopied2) ]
                                              • Set Variable [ $DirectoriesCopied1; Value:MBS( "JSON.GetPathItem"; $json; "DirectoriesCopied"; 3 ) ]
                                              • Set Variable [ $DirectoriesCopied2; Value:MBS( "JSON.GetPathItem"; $jsonResult; "DirectoriesCopied"; 3 ) ]
                                              • Set Variable [ $json; Value:MBS( "JSON.SetPathItem"; $json; "DirectoriesCopied"; $DirectoriesCopied1 + $DirectoriesCopied2 + 1) ]
                                              • Set Variable [ $BytesCopied1; Value:MBS( "JSON.GetPathItem"; $json; "BytesCopied"; 3 ) ]
                                              • Set Variable [ $BytesCopied2; Value:MBS( "JSON.GetPathItem"; $jsonResult; "BytesCopied"; 3 ) ]
                                              • Set Variable [ $json; Value:MBS( "JSON.SetPathItem"; $json; "BytesCopied"; $BytesCopied1 + $BytesCopied2) ]
                                              • Else
                                              • #copy one file
                                              • Set Variable [ $r; Value:MBS( "Files.ReadAndWriteFile"; $ItemPath; $ItemDest ) ]
                                              • If [ MBS("IsError") ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "Error"; "Failed to copy file") ]
                                              • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "ErrorDetail"; $r) ]
                                              • Exit Script [ Result: $json ]
                                              • End If
                                              • #handle statistics
                                              • Set Variable [ $FileSize; Value:MBS( "Files.FileSize"; $ItemPath ) ]
                                              • Set Variable [ $FilesCopied; Value:MBS( "JSON.GetPathItem"; $json; "FilesCopied"; 3 ) ]
                                              • Set Variable [ $json; Value:MBS( "JSON.SetPathItem"; $json; "FilesCopied"; $FilesCopied + 1) ]
                                              • Set Variable [ $BytesCopied; Value:MBS( "JSON.GetPathItem"; $json; "BytesCopied"; 3 ) ]
                                              • Set Variable [ $json; Value:MBS( "JSON.SetPathItem"; $json; "BytesCopied"; $BytesCopied + $FileSize) ]
                                              • End If
                                              • #next
                                              • Set Variable [ $index; Value:$index + 1 ]
                                              • Exit Loop If [ $index > $count ]
                                              • End Loop
                                              • End If
                                              • Exit Script [ Result: $json ]
                                              Fields used in this script
                                                Scripts used in this script
                                                Layouts used in this script
                                                  Tables used in this script
                                                    Table occurrences used by this script
                                                      Custom Functions used by this script
                                                        Custom menu set used by this script

                                                          Previous Script: [CopyFolder Recursive]
                                                          Script NameCopyFolder
                                                          Run script with full access privilegesOff
                                                          Include In MenuYes
                                                          Layouts that use this script
                                                          Scripts that use this script
                                                            Script Definition
                                                            Script Steps
                                                            • Set Variable [ $SourcePath; Value:FileOperation::SourcePath ]
                                                            • Set Variable [ $DestPath; Value:FileOperation::DestinationPath ]
                                                            • Set Variable [ $json; Value:"{}" ]
                                                            • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "SourcePath"; $SourcePath ) ]
                                                            • Set Variable [ $json; Value:MBS( "JSON.AddStringToObject"; $json; "DestPath"; $DestPath ) ]
                                                            • Perform Script [ “CopyFolder Recursive”; Parameter: $json ]
                                                            • Set Variable [ $$result; Value:Get(ScriptResult) ]
                                                            • Show Custom Dialog [ Title: "done"; Message: $$result; Default Button: “OK”, Commit: “Yes” ]
                                                            Fields used in this script
                                                            Scripts used in this script
                                                            Layouts used in this script
                                                              Tables used in this script
                                                              Table occurrences used by this script
                                                              Custom Functions used by this script
                                                                Custom menu set used by this script

                                                                  Download example: FileOperation

                                                                  Used functions:




                                                                  Links
                                                                  MBS Xojo tutorial videos

                                                                  Start Chat