AppleScriptObjC help button

Hi all,


I found how to display a help button in alerts using the setShowsHelp command.

I want to display a short text in a simple window (another alert?) when the user clicks this button.

I'm good in Applescript but totally beginner in AppleScriptObjC.

😉

Posted on Jul 28, 2016 2:41 AM

Reply
4 replies

Jul 28, 2016 8:31 AM in response to ionah

All the setShowsHelp: method does is put a help button in the alert - is is up to you to implement it. The first step is to set the delegate for the alert (your AppDelegate, for example) and add an alertShowHelp: handler to it. When that is done the handler will be called when the help button is clicked. To put up your own alert, take a look at other methods of the NSAlert class:


set alert to current application's NSAlert's alloc's init()
alert's setMessageText:"Alert"
alert's setInformativeText:"Information"
alert's runModal()

Jul 28, 2016 11:14 AM in response to red_menace

Hi!


I'm in a script applet context. It's not an XCode app.

I can't see how is it possible to set the delegate in this case.


My script is similar to this example:

set alert to current application'sNSAlert'salloc'sinit()

alert's setMessageText:"The alert text."

alert's setInformativeText:"The complementary message."

alert'ssetShowsHelp:true

alert'srunModal()

How to intercept the click on the help button?

😕

Jul 28, 2016 1:25 PM in response to ionah

In order to use various delegate protocols you need to have something that you can specify as a delegate. This is usually a script file such as AppDelegate in an Xcode application or CocoaAppletAppDelegate in an application created from the Cocoa-AppleScript Applet template, but it can be a any script object.


From the Script Editor, if you show the bundle contents you will see the CocoaAppletAppDelegate file - you can put stuff in there, but in this example we'll just use the default main script that the Applet provides. If you paste the following example into the main script of a new Cocoa-Applet and save it as an application, it will present a second help alert when the help button is pressed.


script MyDelegate -- this will contain any delegate methods

  on alertShowHelp:alert -- handle a help button
    parent's (makeAlert("The Help text.", "There is no help for you."))'s runModal()
    return true -- the help request has been handled
  end alertShowHelp:

end script

on run -- example
  tell makeAlert("The alert text.", "The complementary message.")
    its setDelegate:MyDelegate
    its setShowsHelp:true
    its runModal()
  end tell
  tell me to quit
end run

on makeAlert(messageText, infoText) -- make a simple alert object
  tell current application's NSAlert's alloc's init()
    its setMessageText:messageText
    its setInformativeText:infoText
    return it
  end tell
end makeAlert


For stuff like this, using Xcode helps a bit since it has logs that you can use, although Xcode itself it quite the beast all by itself.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScriptObjC help button

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.