Monday, December 9, 2019

#1 2019-08-01 11:52:13 pm

moonmonkey
Member
Registered: 2014-12-31
Posts: 8

Trouble with delays

Hi, I have had a good search but can't find the solution to my problem or how to implement it.


I have a process running in the background that I want to poll to determine that more than zero items match the criteria (I got this working). the problem is it locks up my app, I have tried

delay 1
and
do shell script "sleep 1"
in the forums people talk about performSelector:withObject:afterDelay: - but I have been trying for a couple of hours to get that working and I am just stuck, any ideas.

Applescript:



repeat while criteria > 0

say "running"

-- what delay code can I use :)

end repeat


Filed under: delay asoc time

Offline

 

#2 2019-08-02 12:13:17 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6064

Re: Trouble with delays

Use something like this:

Applescript:

on checkProgress()
   -- check whatever here
   if stillWaiting then
       my performSelector:"checkProgress" withObject:(missing value) afterDelay:1.0
   else
       -- do your stuff
   end if
end checkProgress


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2019-08-02 03:52:04 am

moonmonkey
Member
Registered: 2014-12-31
Posts: 8

Re: Trouble with delays

Thanks so much that did it!

Amazing.

I find Apples documentation so impenetrable at times, really appreciate your help with this.

Offline

 

#4 2019-08-02 04:46:59 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11626
Website

Re: Trouble with delays

Polling is worst case and should be used only if you have no choice.

A better practice is to call a handler or send a notification in the background process


regards

Stefan

Offline

 

#5 2019-08-02 08:34:05 pm

moonmonkey
Member
Registered: 2014-12-31
Posts: 8

Re: Trouble with delays

OK I spoke to soon, I have a feeling I'm misunderstanding what's going on.

Basically I want it to keep checking until IsCount is 10.

This is my current code, but its not working,

   

Applescript:


on checkProgress:sender

if IsCount < 10 then
say "running"
my performSelector:"checkProgress" withObject:(missing value) afterDelay:1.0
else
say "finished"
end if

end checkProgress:

when I trigger checkProgress
I get this:


2019-08-03 12:32:30.149827+1000 background checker[32492:20740617] *** -[AppDelegate checkProgress]: unrecognized selector sent to object <AppDelegate @0x6000002979e0: OSAID(4) ComponentInstance(0x810000)>
2019-08-03 12:32:30.150054+1000 background checker[32492:20740617] [General] *** -[AppDelegate checkProgress]: unrecognized selector sent to object <AppDelegate @0x6000002979e0: OSAID(4) ComponentInstance(0x810000)>
2019-08-03 12:32:30.151015+1000 background checker[32492:20740617] [General] (
    0   CoreFoundation                      0x00007fff435672fd __exceptionPreprocess + 256
    1   libobjc.A.dylib                     0x00007fff6dc38a17 objc_exception_throw + 48
    2   AppleScriptObjC                     0x00007fff41886c7f -[BAObjectProto methodSignatureForSelector:] + 0
    3   CoreFoundation                      0x00007fff4350918f ___forwarding___ + 1485
    4   CoreFoundation                      0x00007fff43508b38 _CF_forwarding_prep_0 + 120
    5   Foundation                          0x00007fff4575d6fa __NSFireDelayedPerform + 411
    6   CoreFoundation                      0x00007fff434d0060 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    7   CoreFoundation                      0x00007fff434cfc0c __CFRunLoopDoTimer + 851
    8   CoreFoundation                      0x00007fff434cf752 __CFRunLoopDoTimers + 330
    9   CoreFoundation                      0x00007fff434b0962 __CFRunLoopRun + 2130
    10  CoreFoundation                      0x00007fff434afebe CFRunLoopRunSpecific + 455
    11  HIToolbox                           0x00007fff4270f1ab RunCurrentEventLoopInMode + 292
    12  HIToolbox                           0x00007fff4270eee5 ReceiveNextEventCommon + 603
    13  HIToolbox                           0x00007fff4270ec76 _BlockUntilNextEventMatchingListInModeWithFilter + 64
    14  AppKit                              0x00007fff40aa779d _DPSNextEvent + 1135
    15  AppKit                              0x00007fff40aa648b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1361
    16  AppKit                              0x00007fff40aa05a8 -[NSApplication run] + 699
    17  AppKit                              0x00007fff40a8fae8 NSApplicationMain + 777
    18  background checker                  0x0000000100000f55 main + 101
    19  libdyld.dylib                       0x00007fff6f4063d5 start + 1
    20  ???                                 0x0000000000000003 0x0 + 3
)

Offline

 

#6 2019-08-02 08:53:10 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6064

Re: Trouble with delays

You've changed the method from checkProgress to checkProgress: with an argument, so you need to change the selector and object (if you use it) accordingly.

Applescript:

my performSelector:"checkProgress:" withObject:sender afterDelay:1.0


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2019-08-02 11:19:55 pm

moonmonkey
Member
Registered: 2014-12-31
Posts: 8

Re: Trouble with delays

Thanks, that did it.
I also bought your book, hopefully will stop me having to ask for too much help.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)