AppleScript, Ruby, Threads and Unix... help!!!
-
A few of you know I've been messing with this mix for far too long now, and some may know I finely got some things working.
I have a robust way of manipulating SU with AppleScript from SU ruby.
I can seed the Applescript with returns from Ruby before running in 'osascript' and I have a roundabout, but fast way of getting returns from AppleScript back into ruby.But it's all a bunch of disjointed snippets that I want to pull together in public, where I can hopefully get some help and advice.
Jeff's suggested a sort of 'milestone' idea in another thread that I may use as the first target, my own begin more 'grandiose'.With all my detours I haven't been paying enough attention to 'basic' ruby, although I have been using system ruby from SU to do some bits quite successfully.
The main reason I've used it is I don't know how to get SU ruby to 'wait' without causing beach-balling.
a simple example is when I write a file in one process and close it, unless I have a button or message box, SU ruby will error when I try to read that file, or it will read it before it's updated, I have tried moving, renaming, exist?, is_readable? and goodness knows what else, but without physical delay i can't figure it out...
hope for assistance
john -
The only way that we can "wait" to do something in SketchUp without "beach-balling/whiteout" (because SU controls when Ruby runs,) is to use a timer loop:
@tid = UI.start_timer(@delay, true) { if @file_is_ready_to_read @UI.stop_timer(@tid) read_my_file() # call a local method end }
So the code that writes the file needs to set the
@file_is_ready_to_read
boolean totrue
.If this happens in another process, you would need something like TBD's sub.exe to trigger the variable change, or perhaps DRB (distributed Ruby.)
... Or some kind of net protocol like a UDP message from one process to another.
-
Cheers Dan,
I'm sure a timer before but will revisit... for the moment a couple of us have highjacked Jeffs thread, to work a few thing out... I'll post some bits back here when there usable...
john
Advertisement