I’m trying to convert a studio app into asoc, and ran into some trouble with repeat, delay, and do shell script “sleep x”. So, this is a 2 part question. Part 1:
I need to pause before continuing. In applescript studio, this was just
delay 10
I changed this to
on buttonClicked_(sender)
performSelector_withObject_afterDelay_("logSomething:", "test", 10)
-- do lots of stuff
end buttonClicked_
on logSomething_(x)
log x
end logSomething
The problem with this is that while it waits to log something, it continues to “do lots of stuff” right away. I can move “do lots of stuff” into logSomething, but is there any other way to hold off until logSomething is completed before continuing?
part 2: A similar issue, but with NSTimer. Originally in studio, I had this:
repeat 10 times
delay 3
if (do shell script "ls ~/Downloads") contains "newFile" then
set newFileExists to true
exit repeat
else
set newFileExists to false
end if
end repeat
The main point of the script is that after about 30 seconds, the script continues when a file name “newFile” isn’t there. I tried changing it to this in asoc:
set repeatTimer to current application's NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(3, me, "checkForFile:", missing value, true)
set absoluteTimer to current application's NSTimer's scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(30, me, "killTimer:", missing value, false)
on checkForFile_(sender)
if (do shell script "ls ~/Downloads") contains "newFile" then
set newFileExists to true
repeatTimer's invalidate()
end if
end checkForFile_
on killTimer_(sender)
set newFileExists to false
repeatTimer's invalidate()
end killTimer_
This also continues with the rest of the script before the 30 seconds are up and the rest of the script doesn’t know whether a new file is there or not. Is there any way to pause the rest of the script until this is done? Also, I haven’t been doing this for too long, so I might be thinking about it incorrectly, but I appreciate any input you may have. Thanks!