• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Modifying Library to Run NSAlert on main thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modifying Library to Run NSAlert on main thread


  • Subject: Re: Modifying Library to Run NSAlert on main thread
  • From: Shane Stanley <email@hidden>
  • Date: Wed, 20 Jul 2016 23:20:37 +1000

On 20 Jul 2016, at 10:56 PM, Jacob M. Small <email@hidden> wrote:

I’m using Dialog Toolkit 1.0.3 by Shane Stanley. But I’m writing in Script Debugger 6, which is problematic because the Dialog Toolkit commands need to be run on the main thread, which Script Debugger 6 doesn’t seem to support yet. 

So I’m trying to adapt the approach in Chapter 26 of Everyday AppleScriptObjC for ensuring that Dialog Toolkit’s handler that creates the NSAlert is always run on the main thread.

For this, I’m kind of bumbling around in the dark, as ASObjC is pretty new to me. I’ll paste the handler twice below, first prior to my edit and then with the edit suggested in Everyday AppleScriptObjC. My question is whether my modification will permanently remove the need for me to be concerned about using this library on the main thread, or if I need to find a different approach.

The modification is after the tell block for theAlert. I’ve just added its performSelectorOnMainThread:"displayAlert:" withObject:theAlert waitUntilDone:true within the handler. I’m asking because I don’t quite understand yet what this is doing, just following the book’s instructions.

You're on the right track, but there's a problem: performSelector... doesn't return a result. Without that, you don't know what button was pressed.

The solution is to (a) make returnCode a property, and (b) perform a whole handler using performSelector....

So with returnCode a property, you have a new handler like this:

-- this handler needs to be called on the main thread
on showTheAlert:theAlert
-- check we are running in foreground
if not (current application's NSThread's isMainThread()) as boolean then error "This handler must be called on the main thread." from current application
set my returnCode to theAlert's runModal()
end showTheAlert:

And then you replace set returnCode to theAlert's runModal() with the following:

my performSelectorOnMainThread:"showTheAlert:" withObject:theAlert waitUntilDone:true

Unfortunately that's not quite the end of things -- in a couple of places the script calls fitToSize(), and that too needs to be run on the main thread.

The good news is that I have a new version that works exactly the same as the old version, but has the required changes. The bad news is that I haven't had time to finish testing it so I can post it. But if you (or anyone else) would like to test it, email me off-list.

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Modifying Library to Run NSAlert on main thread
      • From: Shane Stanley <email@hidden>
References: 
 >Modifying Library to Run NSAlert on main thread (From: "Jacob M. Small" <email@hidden>)

  • Prev by Date: Modifying Library to Run NSAlert on main thread
  • Next by Date: Re: Help for optimization of my script
  • Previous by thread: Modifying Library to Run NSAlert on main thread
  • Next by thread: Re: Modifying Library to Run NSAlert on main thread
  • Index(es):
    • Date
    • Thread