1 2 Previous Next 16 Replies Latest reply on Oct 10, 2016 10:07 AM by mrvanbeurden

    Windows version of AppleScript


      Thanks to the very smart and helpful John Renfrew I use the following AppleScipt to check whether FileMaker is the front-most application on Mac. Now the user may have some Windows machines connecting, an almost alien environment to me!

      Can anyone convert this foe me?






      "set var to get the name of the front window" & ¶ &


      "set scriptName to \"" & $script & "\""& ¶ &

      "set var3 to \"FileMaker Pro Advanced\"" & ¶ &

      "set var2 to the name of application (path to frontmost application as text)" & ¶ &

      "if var2 = var3 then" & ¶ &

        //"activate" & ¶ &

        "do script scriptName" & ¶ &

      "end if"

        • 1. Re: Windows version of AppleScript

          The equivalent languages on Windows is VBscript and PowerShell.  Problem is that there is no equivalent of the "Perform AppleScript" script step on Windows.  I've been lobbying for that for your years...


          So while you can write the equivalent code, there is no elegant way to have it execute and return a result to FM.

          • 2. Re: Windows version of AppleScript

            Thanks Wim, shows just how much I know about Windows!

            • 3. Re: Windows version of AppleScript
              Mike Duncan

              Something that has worked for me, in certain instances, is to put all the vbscript in a global field, then export field contents with the option to automatically open where you specify the file output. Works well, but is potentially fragile, so test it thoroughly.


              Also, you may want to clean up the leftover vbscript once done, but as Wim mentions, there is not really an elegant way of telling when the script has completed or getting feedback into FM.


              Still, this can be a powerful option for automating actions with FileMaker on Windows.

              • 4. Re: Windows version of AppleScript

                whilst there is no native way to execute commands in windows, be sure to check out the open source Base Elements plugin BaseElements Plugin | Goya Pty Ltd which has an "Execute script" command and is open source. provides some other very handy file access etc functions as well.

                • 5. Re: Windows version of AppleScript

                  Ah mwilson - you may have something there. I am using the BaseElemenst plugin, and the BE_ExecuteSystemCommand might be what I need - but I suspect there is no way to get the result back into FileMaker as Wim indicated

                  • 6. Re: Windows version of AppleScript

                    The BaseElements plugin will return the result of the command.  So for instance if you do "dir" it will return the output of that to FM in the variable or field that use for the plugin call.


                    So if you make your Windows script (VBscript / PowerShell) output someting, the plugin will return it.

                    • 7. Re: Windows version of AppleScript

                      It's worth noting that you can return parameters to FM using the fmp url protocol.


                      I use AutoIt scripts compiled into .exe files to do this kind of thing on Windows and then return the results with fmp://

                      • 8. Re: Windows version of AppleScript

                        OK Tim, got it working after a fashion


                        Requires a compiled AutoIt scripts (attached) and a bit of juggling with FMP scripts, and the BaseElements plugin


                        Your on timer script fires dispatcher script every n secs and this sets a $var of your script to be the return callback

                        then set a $var2 to the file name (then change path as required!!)

                        BE_ExecuteSystemCommand ( "E:\fmpFront.exe " & Get( FileName ) & "  & $scriptToRun" ) !! there are important spaces in this lot !!


                        This compiled exe look at at the state of the fmp window and if it is hidden exits otherwise it will run the script you told it to in that file using the fmp url

                        Effectively freezes the running of the second script...


                        the AutoIt code for it is

                        $file = $CmdLine[1]

                        $script = $CmdLine[2]

                        $fmState = WinActive("FileMaker Pro Advanced")

                        If $fmState = "0" Then



                          ShellExecute("fmp://$/" & $file & "?script=" & $script )



                        Simples... clearly needs a bit more work in the complied version if you are just running pro...



                        • 9. Re: Windows version of AppleScript

                          I tried this with PowerShell, got worked. This need BE plugin only.




                          PatternCount ( BE_ExecuteSystemCommand ( cmd ) ; "True" )



                          This can be a custom function. So the TimAnderson's script in windows will be like

                          If [ cf ]

                            Perform Script [scriptname]

                          End If


                          The long string is BASE64 encoded command of below.


                          Add-Type @"

                            using System;

                            using System.Runtime.InteropServices;

                            public class UserWindows {


                              public static extern IntPtr GetForegroundWindow();



                          try {

                          $ActiveHandle = [UserWindows]::GetForegroundWindow()

                          $Process = Get-Process | ? {$_.MainWindowHandle -eq $ActiveHandle}

                          $isfg = $Process | Select @{Name="isFg"; Expression = {$_.ProcessName -match "FileMaker Pro(| Advanced)" -and $_.MainWindowTitle -match "FileMaker Pro(| Advanced)"}}

                          $isfg | Format-Wide

                          } catch {

                              Write-Error "Failed to get active Window details. More Info: $_"



                          I'm newbie of PS, so there may be something better.

                          (at least, returning boolean value as number may be better than string...)

                          • 10. Re: Windows version of AppleScript

                            Thank you everybody, will be something I can use there. Users may not be allowed to install exe files on their computers so the encoded Powershell example from User19752 may be what we need.

                            • 11. Re: Windows version of AppleScript

                              This is a really neat solution... Tried it in place of the AutoIt script in the demo file I did and it works just as well with fewer moving parts.

                              I might be missing something but the text as it is there does not seem to B64 encode to that string

                              Was going to quickly make a second version with FM Pro - or does that do it already?



                              Great bit of code that's going in my toolbox straight away.

                              • 12. Re: Windows version of AppleScript

                                You can decode the text using FM script as


                                Set Field[container; Base64Decode("the text")]

                                Export Field Contents[container]


                                If you use Base64Encode() function, it returns line broken string, so the result is different.

                                To encode, I used another ps script


                                $command = {

                                here is commands to encode


                                $encodedCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($command))

                                "powershell.exe -EncodedCommand $encodedCommand" | clip.exe


                                Sorry for my English, what do you mean as "second version" ? I assume you are afraid of using on FM Pro.

                                The command use -match with regex, so run on both Pro and Advanced.


                                I can't imagine when the script get error for getting foreground window (anytime there is a foreground window, isn't it?), but Write-Error parameter is better to not contain $_, since if it returns some text containing "True", error is treated as "FM is foreground" in my custom function.

                                • 13. Re: Windows version of AppleScript

                                  as far as fmp:// returning parameters, I have successfully handed around approx 32MB of base64 encoded text between fm11go and fm12 go on iPad when I was evaluating it for IAC using filemaker as my core logic engine, with specific functions with optional access to gyro/GPS/etc written in compiled code (plugins)

                                  • 14. Re: Windows version of AppleScript

                                    I made the code as "is FM Pro or Advanced foreground" function, but more simply returning "Foreground window title" may be better since Pro and Advanced can run simultaneously.


                                    And, I found that when sub window (Manage database, Data viewer, etc) open, this code don't return "true".

                                    1 2 Previous Next