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.
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.
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.
I was able to use the send event using Script Editor 2.2 and following the instrctions here:
hope this helps
I got Script Editor 2.2 from a previous os x installation. I hope you have one too.
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.
Can you confirm that this is also the case with Filemaker 11.03? Original report is for 10.03.
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.
I don't have a Mac so I cannot test an AppleScript issue. That's why I asked and thanks for the additional info.
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"
See attached screenshot, hope this helps..
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
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.