Delay an event without freezing App

Hi folks. Im trying to delay a button from enabling in an Interface builder window, this is the code Ive tried.

            tell demoModeWindow to makeKeyAndOrderFront_(me)
            set enabled of registerApp to true
            delay 5
            set enabled of demoContinueButton to true

As you may have guessed, that causes the whole App to freeze up during the delay, even the code just before the action seems to not run until the dealy is done. That could just be a lag showing the window of the App i guess tho.

Any have any ideas of a way round this?

Much appreciated.

PS this runs in the awakeFromNib code.

Well, first of all you should stop using the delay command. This will cause you more problems than help. When using ASObjC there is much, much better alternatives

Here is a list of instance methods from NSObject that can help replace delay:

“ performSelector:withObject:afterDelay:
“ performSelectorOnMainThread:withObject:waitUntilDone:
“ performSelector:onThread:withObject:waitUntilDone:
“ performSelectorInBackground:withObject:

I would personally recommend the first and last items in this list. Main difference is the last one will not freeze your app, but first one might, depending on the method you are asking to perform.

There is plenty of examples in these forums about these 2 methods, it should get you started rather quickly. Or search in Google for these search terms:

macscripter performSelector
macscripter performSelectorInBackground

Good luck!

Browser: Safari 534.51.22
Operating System: Mac OS X (10.8)

Great thank you! Will have a look around.