Shakti
Shakti

Reputation: 1959

Adding action to menu item

I have added a menu item to menu controller window by dragging a item from library. Now i want to provide a action to that menu such as on click that menu item a applescript file should run. Can any body help me out this?

Upvotes: 2

Views: 1270

Answers (1)

Peter Hosey
Peter Hosey

Reputation: 96323

Declare an action method in your controller's header, then save the header file. Then, in IB, ctrl-drag from the menu item to the controller, and choose the action you just declared.

[Edit from the year 2013: Or, in Xcode 4, open the nib in a main editor and the header—or implementation file with a class extension in it—in an assistant editor, then ctrl-drag from the menu item to the @interface and create an action using the resulting popover.]

Then, in the controller's implementation file, implement the action method. You'll need to create either an OSAScript (using OSAKit.framework—no docs; you'll need to read its headers) or an NSAppleScript (using AppKit) instance and tell it to execute.

Upvotes: 4

Related Questions