Hi,
i generated a small interface called ‘IPODLAS’ with Interface Builder containing an applescript IPODLAS.applescript.
In this script i try to catch the AppleEvent receiveMessage:
…
on receiveMessage()
display dialog “Animation finished” buttons {“OK”} default button 1
end receiveMessage
this AppleEvent should be sent by an other appleScript sendAE2IPODLAS.applescript:
tell application “IPODLAS” to receiveMessage()
when IPODLAS is running and i try to run the sendAE2IPODLAS.applescript, I get allways the error:
AppleScript Error
IPODLAS got an error: Can’t continue receiveMessage.
The application IPODLAS seems to be found, but not the handler.
Only AppleScript applets support this behaviour; Cocoa apps do not. Unfortunately, it’s not possible to implement proper scripting support in Studio-based apps, though one common workaround is to add a hidden GUI widget to the app’s UI and have the external script send events to that. It’s rather hackish and limited in what it can do, but for what you describe it’s probably your simplest option.
Hi,
thanks for your hint, i only don’t quite get it.
You mean, generating a hidden widget in the Interface builder app and to catch with this widget the respective appleevent (how is this done?) and to extract the relevant data?
Add a button named “hidden button” and text field named “hidden field” to the main window. Connect the button’s ‘clicked’ handler to the application’s script. To hide the widgets from view, set their coordinates to a negative value.
Add the following event handler to the application’s script:
on clicked theObject
if theObject's name is "hidden button" then
say (content of text field "hidden field" of window 1) as string
end if
end clicked
Build and run the application.
Run the following script in SE, and the app should say “hello”:
tell application "your app"
set content of text field "hidden field" of window 1 to "hello"
perform action button "hidden button" of window id 1
end tell
It’s horribly crude, but it should work.
Another option would be to connect the application’s open handler and use something like:
on open theObject
if theObject's class is record then -- not a type it should normally receive
if theObject's name is "foo" then
foo(theObject's params)
else if theObject's name is "bar" then
bar(theObject's params)
end if
else
-- handle open event normally
end if
end open
To call a handler you’d then send it an command like:
tell app "your app" to open {name:"foo", params:{1, 2, 3, 4}}
Also horribly crude, but like I say there’s no particularly good solution to this problem. Feel free to file a feature request with Apple about it.
Hi, I was just browsing for a solution to a different problem entirely but I have to say, “Damn if that aint sneaky.” I never would have thought of that.
Browser: Safari 412.2
Operating System: Mac OS X (10.4)