LiveCode for FM ManualGetting StartedHow do I include LiveCode for FM in my solution?

How do I include LiveCode for FM in my solution?

Example solution

The example solution discussed in this lesson includes a table, layout and script that shows how to include and update the LiveCode for FM plugin in your solution, activate the licensed seat and and install custom components. Please download it before continuing.

Create the table and layout

In the example solution the table is named LiveCodeUpdate. If you choose to name the table or fields differently then you will need to modify the script to reference the correct fields.

The table includes the following fields:

  • Build - the LiveCode for FM build number. For example, 15010
  • Windows x86_64 - a container field for the windows 64 bit build
  • Windows x86 - a container field for the windows 32 bit build
  • Mac - a container field for the mac build
  • Error - a text field that will be set to an error value if update fails
  • License - a container field for a license file LiveCode. You can be downloaded a license file from your LiveCode for FM Account page by clicking "Generate license key file."
  • Passphrase - a text field for the passphrase used when the license file was created
  • Components - a container field for packaged components

The example layout also includes a Choose... button next to the components field. This is to make it easy to choose custom components to be included in the components package if you have created some that you want to use in your solution.

Copy the plugin files to the container fields:

  • Windows x86_64 should contain the .fmx64 file
  • Windows x86 should contain the .fmx file
  • Mac should contain the .fmplugin bundle

If you know your solution will only be deployed on one or two of the supported build architectures then there is no need to copy the file to the field for the others. For example, if your windows installations are all 64 bit there is no need to include the 32 bit windows build.

Set the Build field to the build number of the plugin.

In your user account on filemaker.livecode.com create a license file and copy it to the License container field. Enter the passphrase used to create the license file into the Passphrase field.

Copy the LiveCodeUpdate script

The LiveCodeUpdate script is intended to be used with an OnFirstWindowOpen script trigger to ensure that LiveCode for FM is installed and activated as soon as your solution is opened.

The following steps are involved in the script:

  1. Check if an older version is installed and delete if it is
  2. Install the plugin if it is not installed
  3. Activate the plugin with the license file
  4. Install any packaged components

The script is included below for reference and can be copied from the example solution file.

Go to Layout [ “LiveCodeUpdate” ]
Go to Record/Request/Page [ First ]

#ensure the failure notice is cleared
Set Field [ LiveCodeUpdate::Error; "" ]

Set Variable [ $current_build; Value:Let ( [ PluginLineStart = Position ( Get(InstalledFMPlugins); "LiveCodeForFM;" ; 1 ; 1 ); PluginLineEnd = If ( Position ( Get(InstalledFMPlugins); "¶" ; PluginLineStart ; 1 ) > 0 ; Position ( Get(InstalledFMPlugins); "¶" ; PluginLineStart ; 1 ) ; Length( Get(InstalledFMPlugins) ) + 1 ); PluginLineLength = PluginLineEnd - PluginLineStart; PluginLine = Middle ( Get(InstalledFMPlugins) ; PluginLineStart ; PluginLineLength ); PluginBuildNumberStart = Length( "LiveCodeForFM" ) + 2; PluginBuildNumberEnd = If ( Position ( PluginLine ; "-" ; PluginBuildNumberStart ; 1 ) > 0; Position ( PluginLine; "-" ; PluginBuildNumberStart ; 1 ); Position ( PluginLine; ";" ; PluginBuildNumberStart ; 1 ) ); PluginBuildNumberLength = PluginBuildNumberEnd - PluginBuildNumberStart ]; If ( PluginLineStart ; Middle ( PluginLine ; PluginBuildNumberStart ; PluginBuildNumberLength ) ) ) ]
Set Variable [ $is_update; Value:$current_build ≠ "" ]

#Check if we need to update
If [ not $is_update or $current_build < LiveCodeUpdate::Build ]
   Set Error Capture [ On ]

   #Workaround Windows plugin installation issue
   If [ Get(SystemPlatform) = -2 ]
      If [ $is_update ]
         If [ Get(ApplicationArchitecture) = "x86_64" ]
            Set Variable [ $existing_plugin_file; Value:"livecodeforfm.fmx64" ]
         Else
            Set Variable [ $existing_plugin_file; Value:"livecodeforfm.fmx" ]
         End If
         
         Set Field [ LiveCodeUpdate::Error; "A version of LiveCode for FM is installed which cannot be automatically updated. " & "In order to update, please do the following:" & ¶ & " 1. Open the FileMaker Extensions folder (via Edit > Preferences > Plug Ins > Reveal Extensions Folder)." & ¶ & " 2. Close FileMaker." & ¶ & " 3. Delete '" & $existing_plugin_file & "'" & ¶ & " 4. Delete '" & $existing_plugin_file & ".resources'" & ¶ & " 5. Open FileMaker again." & ¶ & " 6. Open this solution." & ¶ & "This problem will be fixed in a future build." ]
         Halt Script
       End If

       If [ Get(ApplicationArchitecture) = "x86_64" ]
          Install Plug-In File [ LiveCodeUpdate::Windows x86_64 ]
       Else
          Install Plug-In File [ LiveCodeUpdate::Windows x86 ]
       End If
    Else If [ Get(SystemPlatform) = 1 ]

       #Plugin update required for the moment we need to check if the user wants to restart FileMaker
       If [ $is_update ]
          #Confirm with user
          Show Custom Dialog [ Title: "Restart Required"; Message: "Clicking `Continue` will remove the plugin and quit FileMaker. Re-opening the solution will install the plugin. Clicking `Cancel` will close this solution. This issue will be fixed in a future release."; Default Button: “Continue”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]
          If [ Get ( LastMessageChoice ) = 2 ]
              Close File [ Current File ]
              #Just to be sure
              Halt Script
          End If

          #Delete the plugin manually
          Set Variable [ $filemaker_version; Value:Let([ FileMakerVersion = RightWords ( Get (ApplicationVersion) ; 1 ); FileMakerShortVersionLength = If ( Position ( FileMakerVersion ; "." ; 1 ; 2 ) ; Position ( FileMakerVersion ; "." ; 1 ; 2 ) - 1; If ( Position ( FileMakerVersion ; "v" ; 1 ; 1 ) ; Position ( FileMakerVersion ; "v" ; 1 ; 1 ) - 1; Length ( FileMakerVersion ) ) ); FileMakerShortVersion = Middle ( FileMakerVersion ; 1 ; FileMakerShortVersionLength ) ]; FileMakerShortVersion) ]
          Perform AppleScript [ Calculated AppleScript: Let ([ FileMakerEdition = LeftWords ( Get (ApplicationVersion) ; 1 ); FileMakerEditionName = If ( FileMakerEdition = "ProAdvanced" ; "FileMaker\\\ Pro\\\ Advanced"; "FileMaker\\\ Pro" ); PluginPath = "~/Library/Application\\\ Support/FileMaker/" & FileMakerEditionName & "/" & $filemaker_version & "/Extensions/livecodeforfm.fmplugin" ]; "do shell script \"rm -rf " & PluginPath & "\"" ) ]
          
			 Exit Application

          #Just to be sure
          Halt Script
      End If

      Install Plug-In File [ LiveCodeUpdate::Mac ]
   End If

   #handle errors
   If [ Get ( LastError ) ≠ 0 ]
      If [ Get ( LastError ) = 3 ]
        Set Field [ LiveCodeUpdate::Error; "LiveCode for FM could not be installed. Ensure Allow Solutions to Install Files is selected in the FileMaker Pro Plug-in preferences." ]
      Else If [ Get ( LastError ) = 1550 ]
        Set Field [ LiveCodeUpdate::Error; "LiveCode for FM was installed but could not be initialized." ]
      Else If [ Get ( LastError ) = 1551 ]
        Set Field [ LiveCodeUpdate::Error; "LiveCode for FM could not be installed." ]
      Else
        Set Field [ LiveCodeUpdate::Error; "A general error " & Get(LastError) & " occured when installing LiveCode for FM" ]
      End If

      Halt Script
   End If
End If

#Activate the user license
Set Variable [ $status; Value:LCActivate ( LiveCodeUpdate::License;  LiveCodeUpdate::Passphrase ) ]
If [ $status ≠ "licensed" ]
   Set Field [ LiveCodeUpdate::Error; "An error occurred when activating LiveCode for FM. The current license status is " & $status &"." ]
   Halt Script
End If

#Install custom components
Set Variable [ $result; Value:LCInstall ( LiveCodeUpdate::Components ) ]
Click to copy

0 Comments

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.