Satimage Previous | Next
Polling a scriptable application
Home Documentation Smile Computing Working with external codes Making a code scriptable Polling a scriptable application  
The instructions here are helpful if the application that your script controls may take a while to complete some commands.
  • To have a call to an application return immediately, and your script proceed further, use ignoring application responses.
    ignoring application responses
        tell application "MyScriptableApp"
            compute 10000
        end tell
    end ignoring
  • To query safely your application at any time, use with timeout of.
    The with timeout of wrapper changes the timeout from the default (2 minutes) to the specified value (you have to write seconds). If the application has not returned a result when the timeout is elapsed, AppleScript triggers a timeout error.
    on PollApp()
        with timeout of 0.01 seconds
            tell application "MyScriptableApp"
                set the_result to velocity
            end tell
        end timeout
        return the_result
    end PollApp
  • To have your script pause until the computation is complete, poll your application as described above in a loop, and insert smilepause to keep Smile responsive: while your script waits you can use Smile normally.
    repeat
        try
            set v to PollApp()
            exit repeat
        end try
        smilepause 0.01
    end repeat
  • More sophisticated client-server models can be implemented using multi-threading. For an example of a simple threaded application, download the sample code folder from the page below and use the ThreadedApp project for XCode.
Version française
Copyright ©2008 Paris, Satimage