10 Replies Latest reply on Mar 22, 2012 4:46 PM by DavidAGamble

    Unable to Send Event "aevt";"oapp" to Applescript saved as application

    DavidAGamble

      Summary

      Unable to Send Event "aevt";"oapp" to Applescript saved as application

      Product

      FileMaker Pro

      Version

      10.3

      Operating system version

      10.6.5

      Description of the issue

      Unable to set an Applescript saved as application to a Send Event script step if the Applescript was created with Mac OS X 10.6.x. Snow Leopard.  The Applescripts saved as application in earlier OS versions such as 10.5.x and 10.4.x do not have this problem.

      Steps to reproduce the problem

      Create an Applescript and save it as an application in Mac OS X 10.6.x  Create a script in FileMaker Pro.  >>Move>> a Send Event script step into the script window.  Select Specify.  Select Specify Application... button in "Send Event" Options window.  Navigate to the applescript application just created.  Select it and click on the Open button.  The Target Application: will be blank.

      Expected result

      Send Event ["Enter Reports.app";"aevt";oapp"; Enter Reports.app"]

      Actual result

      Send Event["aevt";"oapp"]

      Workaround

      I can execute the Applescript application by double clicking on it in the Finder.

      Send_Event_Screen_Shot.png

        • 1. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application
          danshockley

          This is a big problem for those who use AppleScript with FileMaker. The reason? External AppleScript applications make it possible to interact with FileMaker in ways that are very hard or impossible via the "Perform AppleScript" step. Why? The "Perform AppleScript" step locks up FileMaker until it finishes, so the AppleScript is prevented from doing quite a few things in FileMaker (like running scripts, accessing menu items, and so on). 

          AppleScript has changed in a significant way in recent version of Mac OS X. FileMaker should update the "Send Event" script step to take those changes into account.

          • 2. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application
            danshockley

            I have found a crazy work-around using "Perform AppleScript" combined with a "do shell script" command that redirects all output to /dev/null (or a log file, if you like).

            I call it crazy because it requires several layers of escaping quote characters. Here is an example: 

            "do shell script \"osascript -e 'tell application \\\"My AppleScript App\\\" to someHandlerInMyApp(\\\"String Number 1\\\", \\\"String Number 2\\\", 35)' &> /Users/myusername/Desktop/testout.txt & \"" 

            This will tell the AppleScript application named "My AppleScript App" to run its own internal handler "someHandlerInMyApp" with the parameters:

            "String Number 1", "String Number 2", 35

            Notice the redirecting of the shell output to a file. That is explained in Apple's Technote #TN2065, found at http://developer.apple.com/library/mac/technotes/tn2002/tn2065.html

            You could change that path to /dev/null if you don't care about the output. If that path contains spaces (or certain other characters), they will need to be escaped, or the entire path quoted. 

            Basically, this work-around will be very tricky to use for people who aren't familiar with all of the following, in combination: AppleScript, shell scripts, and UNIX commands, generally. 

            It really would be good if FileMaker acknowledged that the "Send Event" script step no longer works properly on the current Mac OS X, and fixed it. 

            • 3. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application
              danshockley

              Follow-up: If you are not familiar with shell scripting and AppleScript, this will make the crazy work-around a bit less difficult:

              For each parameter you need to send to your AppleScript handler (function), set a variable like this: 

              Set Variable [ $asParam1; Value: Let( escapeParam = "String Number 1"; If( Length( escapeParam ) > 0 and escapeParam = GetAsNumber( escapeParam ); escapeParam; "\\\"" & escapeParam & "\\\"" )) ]

              Set Variable [ $asParam2; Value: Let( escapeParam = "String Number 2"; If( Length( escapeParam ) > 0 and escapeParam = GetAsNumber( escapeParam ); escapeParam; "\\\"" & escapeParam & "\\\"" )) ]

              Then combine them like this:

              Set Variable [ $asParamsTogether; $asParam1 & ", " & $asParam2 ]

              Also set appropriate variables for: $appletName, $handlerName, and  $outputPosix  (where $outputPosix is the POSIX path to your log file - can be blank if not needed). 

              Then set a variable named $asCode to:

              "do shell script \"osascript -e 'tell application \\\"" & $appletName & "\\\" to " & $handlerName & If( PatternCount( "¶run¶launch¶quit¶"; "¶" & $handlerName & "¶" ) > 0   ; ""   ;"(" & $asParamsTogether & ")'"   )& If( Length( $outputPosix ) > 0  ; " &> \" & quoted form of \"" & $outputPosix & "\""  ; " &> /dev/null"  )& " & \" & \""

              Then do a Perform Applescript with $asCode as the Calculated AppleScript. 

              This will run the desired handler in your AppleScript applet, even if it is a bundled application (in other words, your ONLY option in Snow Leopard), without FileMaker waiting for the result, so your applet will be able to work on FileMaker (since the FileMaker script will end). Of course, this won't work if you have Script Debugger running, since that keeps the script from finishing.

              Even with this crazy work-around, I hope FileMaker Inc. will fix this _bug_ in the Send Event script step - it is currently incompatible with Mac OS X 10.6.  

              • 4. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application
                AkinJohnston

                I was able to use the send event using Script Editor 2.2 and following the instrctions here:

                http://www.filemakermagazine.com/articles/learning-applescript.html-0

                hope this helps

                I got Script Editor 2.2 from a previous os x installation. I hope you have one too.

                • 5. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application

                  All:

                  I apologize for the late response but your reports are appreciated.

                  I was also able to reproduce this behavior between Send Event and applications generated by AppleScript Editor 2.3 so I forwarded your posts to our Development and Quality Assurance (testing) departments for further investigation. Thank you.

                  TSBear

                  FileMaker, Inc.

                  • 6. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application
                    philmodjunk

                    TSBear,

                    Can you confirm that this is also the case with Filemaker 11.03? Original report is for 10.03.

                    • 7. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application
                      DavidAGamble

                      PhilModJunk

                      I can confirm the problem is not resolved by upgrading to FMP 11.  Download the demo and try it.  I thought problem concerned 32-bit vs 64-bit applications.  OS X 10.6x is 64-bit, the latest AppleScript Editor is 64-bit.  FMP 10 & 11 are still 32-bit.  I have AppleScript Editor set to open in 32-bit mode, but that didn't help.

                      • 8. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application
                        philmodjunk

                        I don't have a Mac so I cannot test an AppleScript issue. That's why I asked and thanks for the additional info.

                        • 9. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application
                          RonK

                          To work around this I use the, script step "Perform AppleScript", and call the script I want to run

                          tell application "Finder"

                          open alias "Macintosh HD:Dated_Temps:Posting_Tools:Password_Protected_File_Posting:Password_Protected_Script_(No_new_file).app"

                          end tell

                          See attached screenshot, hope this helps..

                          • 10. Re: Unable to Send Event "aevt";"oapp" to Applescript saved as application
                            DavidAGamble

                            Ron K,

                            That did the trick.  I was limping along in Snow Leopard and older versions of the Applescripts written with Script Editor 2.1.1 until I upgraded to Lion.  No more Rosetta.  No more old scripts written with Script Editor 2.1.1.  At that point, I just made aliases of the Applescript apps on my Desktop and double-clicked them. Not very elegant.

                            However, you've hard coded the path to the app file.  I have no control of what the user named the hard disk drive.  Nor do I necessarily know the users name so accessing files in their home directory won't be possible.  How about something like this?

                             

                            set homeFolder to (path to home folder) as string

                            set theApp to homeFolder & "Sub Folder:Another Sub Folder:FileMaker Pro Scripts:The Lion App.app"

                            tell application "Finder"

                              open alias theApp

                            end tell

                            Thanks for your imput.  It was very helpful.  I'm ashamed that I did not think of it myself.  I tried puting the entire Applescript text in the Native AppleScript field, but as indicated in an earlier post (Dan), the script takes over FileMaker until completion.  Now I can keep working while the applet runs.