Jump to content

"Send Apple Event" - can't specify target app!


This topic is 7141 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I want to use a FM script to launch an Applescript application. However, the dialog that comes up when I script "Send Apple Event" won't take my application specification.

I'm telling it to send the open application event (along with Bring App to Foreground, and Wait for Event Completion). When I click Specify Application, the OSX Open dialog allows me to select my app, but after I press Open, the Target Application still displays "<unknown>"

The app is called Direct Download.app; it's an Applescript that's been saved as an application bundle. It runs fine when I double click it.

FMP6.04, Panther.4, Applescript 1.9.3

Any ideas what I'm doing wrong?

Thank you!

Chap

Link to comment
Share on other sites

You're not doing anything wrong. Send event is broken in Filemaker 6.

I much prefer using "perform applesrcript". Send event has some problems - including the one you cite. It doesnt' work anymore.

Link to comment
Share on other sites

Thanks, Bruce.

My Applescript is around 150K, too large to be stored as an internal "Perform Applescript".

I tried an FM script containing simply Perform Applescript["run application "Direct Download.app""]. Selecting it from the FM scripts menu, I get a busy cursor until I hit Cmd-. at which point the Direct Download.app begins running!

Is it normal for FM to go into a Wait after doing Perform Applescript? Do you know if there's a way to sidestep it?

Thank you,

Chap

Link to comment
Share on other sites

Have you tried load script? I'd be curious what happens.

Filemaker is waiting for your app to send a reply. You could try something like this:

tell app "WhopperAS" to dothis()

You app would have an idle loop and a doThis() handler.

property myDelay:20

property goAhead:0

On dothis(fMStuff)

set goAhead to 1

set myDelay to 1

return "thank you fileMaker"

end doThis

on idle

if goahead > 1

dostuff()

end if

return myDelay

end idle

This is the rough idea.

Link to comment
Share on other sites

You can very easily load your whole 100KB + script into a filemaker perform applescript statement. I just did it this way, it worked fine, with a 156kb script.

You only need these two statements in your filemaker perform applescript step. When you attempt to close script editor, it will prompt you for the file and load it. When you run the script, it will work fine.

property bigScript: load script (choose file)

run bigScript

Link to comment
Share on other sites

You only need these two statements in your filemaker perform applescript step. When you attempt to close script editor, it will prompt you for the file and load it. When you run the script, it will work fine.

property bigScript: load script (choose file)

run bigScript

Bruce,

Neat trick. But I'm still having problems with my script.

Perhaps I'm trying to do something inadvisable. This script is a batch loader for the database. It *won't* be replying or ending for anywhere from a minute to several hours.

It's created as an Application Bundle because I've stored several shell scripts in the Resources subdirectory. For the Applescript to compute the path to these scripts, I've included the statement

set gShellScriptDir to (path to me as string) & "Contents:Resources:" & "ShellScripts:"

In some of the error messages I saw, running the script as you described appears to evaluate "path to me" as some subdirectory within Filemaker, *not* the Application Bundle that's sitting on my desktop. Thus it can't find the shell scripts.

And oddly, the lines...

tell application "FileMaker Pro"

tell database gFMPInvoicesTable

try

do script "Get Password" -- FM script, same database

on error myErrMsg

display dialog "BUG: getPGPPass()B) " & myErrMsg

error "Bail out of getPGPPassphrase"

end try

end tell

end tell

... triggers the error block with "Object not found."

I'm going to go back to trying to launch the applescript via the Finder, and try some of the things you suggested about getting past the wait.

Thanks, Chap

Link to comment
Share on other sites

Yes, path to me is path to the current application, and that is FileMaker. So you would have to put in the other path somehow. Sounds like a pretty sophisticated application. Also, if you are doing Filemaker stuff inside filemaker, you should leave off the tell app Filemaker statement. And you may want to use the more complete form: do script filemaker script "Get Password". In the above portion of your script you refer to gFMPInvoicesTable but I assume you set that value somewhere else? Also, it seems to me that sometimes I have had to use the single line form for do script: tell document "XYZ.fp5" to do script FileMaker script "Do this"

Link to comment
Share on other sites

I've decided that it's a lot easier for the Applescript to continue to run as a standalone application, as it was originally developed. Since it's only meant for one client, running OS X, I am able to launch the applescript with a simple FM script that reads:

Perform Applescript ["do shell script "open /posix/path/to/my/applescript.app""]

This launches the applescript and does not put Filemaker into a state of waiting for a response.

Maybe at some point I'll try to compute the path automatically...

Thanks for all of your generous help and suggestions!

Chap

Link to comment
Share on other sites

Well, now I have a question for you. Do you know how to pass a parameter to your applescript with a shell script method like that? Say you have a handler, doThis( X1).

This doesn't seem to work but maybe you'll have an idea, assuming doThis() is a handler in the app?

Perform Applescript ["do shell script "open /posix/path/to/my/applescript.app 'dothis()'""]

Link to comment
Share on other sites

I believe the problem is how to get *anything* to pass parameters to an Applescript. I don't know how to do it. There may be sufficient trickery-potential in Applescript stuff like Libraries and top-level script objects & handlers to accomplish it (or you could always fall back on writing a temp file).

Here's a link that might provide some clues.

http://www.macosxhints.com/article.php?story=20040617170055379#comments

They are using the shell command 'osascript' rather than 'open', which allows you to string together some AS statements, and compile & run them. Maybe you could use that to bootstrap the intended AS program into action with certain settings? Just guessing wildly. :-)

Link to comment
Share on other sites

Well, this is pretty snappy:

set x to "ls > /tmp/a.txt | open -a /Users/bfr/Desktop/MyAPPX.app /tmp/a.txt"

do shell script x

Where the script of MyAPPX is:

on doThis(x)

activate me

display dialog "Do this: " & x

end doThis

on open of theseItems

read item 1 of theseItems

doThis(result)

end open

Link to comment
Share on other sites

  • 2 weeks later...

Excellent! I wasn't aware of Applescript's "on open" statement. Looks like a good candidate for Solutions and Suggestions.

set x to "ls > /tmp/a.txt | open -a /Users/bfr/Desktop/MyAPPX.app /tmp/a.txt"

Miniscule nit - I know it's just an example, but I'd use a semicolon, rather than a pipe, between the 'ls' and 'open' shell commands, just to avoid implying that anything's being piped. Or am I missing something?

Link to comment
Share on other sites

Thanks. Good point. And maybe you can answer a question - how can I get a result back from the above example? It opens the script file does something and returns a result. I don't see how to get the result back from this operation.

Link to comment
Share on other sites

Since the 'open' command doesn't appear to send any output to STDOUT, you can't use

set y to (do shell script x)

Another reason you can't do that is that the 'open' command is asynchronous, launching the app and then terminating.

(When the shell script writes to STDOUT and is synchronous, as almost all are, you can capture the answer via

set y to (do shell script "pwd") -- for example

)

MyAPPX.app could pass its result back to Filemaker via a global field. But the original FM script continues to roll after kicking off MyAPPX.app, opening up the problem of its knowing when MyAPPX has found an answer. The way I would try it is to have FMScript1 fire off 'do shell script x' and then exit; when MyAPPX has its answer it tells Filemaker to set cell 'gFoo' to 'bar', and then tells Filemaker to do script FMScript2.

So, would it work for you to break the Filemaker script in two like that?

It's an interesting problem.

Link to comment
Share on other sites

  • 1 month later...

You're not doing anything wrong. Send event is broken in Filemaker 6.

It only broke when I switched to Panther. Now it sees my target app as a document and won't let me select it.

I can't believe there aren't more people screaming about this. There's got to be some way to get this fixed.

Link to comment
Share on other sites

This topic is 7141 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.