Applescript events in Interface Builder

Im playing with IB, and Applescript as part of the process of getting to know the whole system.

One of the problems Ive had was using IB, so rather than trying to start from scratch I thought it would be fun to fiddle with an existing app.

What I chose to do was add a cache search drawer to safari.
Ive built a draw, and populated it with widgets, and got it to show and hide etc. Now I need to trigger the search code when a term is entered in the text field.

Ive read the documenation on how to add an applescript event to an odject, and it all makes sense. But I dont get a list of scripts in the list field below the event tree, and if I create a new script it doesnt show up in the list. I assume the scripts need to go somewhere specific, but I cant find where that is.

Can anyone tell me where to put scripts to get them to show up in an existing application?
Or, how do I decompile an application so I can add stuff to it?

You handle all stuff from Project Builder (any document called “whatever.pbproj”).
You can add icons, frameworks, new nibs and scripts from there. And any script you add to it, will be shown in Interface Builder, so you can connect events to it.

In order to create a new script in IB, you must open the “MainMenu.nib” from PB (“Files” tab, “Resources” folder, double-click “MainMenu.nib”), so IB knows where to add the stuff. Then, if you hit “new script”, you will see a “target” where create such script, and also see the default “Application.applescript” in the list below.

  • I will move this message to the AppleScript Studio forum!

I started a new PB project, and put some applescript in it, hooked up to a button. Then I built it and inspected the results.

Ive found:

There is a scripts directory in the bundle ( its missing in the Safari bundle ).

  • so Ive added this to the safari bundle, and put a script in it.
    Unfortunately the scripts in here are compiled.
  • How do I compile a script?
  • Can I just write it by hand?

Because of the compiling error I put another compiled script into the folder.

That certainly made IB think a bit when it opened Safari’s nib, but not hard enough.

Grepping the test project revealed objects.nib, which contains some info about the applescript.

So, I need to add this info somehow to the safari nib, any idea?
There is an applescript info object in the instance browser, but it has no attributes.

:shock: Safari? Are you developing Safari, or simply hacking it?
If this is the case, you can’t do it!

I’m not sure how it works, but I think that all the stuff (nibs, scripts, frameworks) are compiled and connected in the build phase, which happens in Project Builder when all is OK (no syntax errors, no missing files).

On the other hand, scripts in AS-Studio are compiled only at build-time. Meanwhile, they are saved as plain-text.

Using Apple’s Script Editor (/Applications/AppleScript/Script Editor), you can write scripts, compile them and save as plain text, compiled script or standalone application.

Cheers :wink:

  • Man, you are very quick in your learning-curve!