dimanche 23 juillet 2017

AppleScript : if and repeat

I created a script to check the status of a web search

I added a repeat statement so the script can continue only if the search is completed or if the "SN" is invalid.

repeat 20 times
    set theSearchstate to "not ready"
    set checkIfSNIsCorrect to ""
    set checkIfSNIsInvalid to ""
    try
        tell application "Google Chrome"
            tell front window's active tab to set checkIfSNIsInvalid to execute javascript "document.getElementsByClassName('modal-body ng-scope')[0].innerHTML;"
            ## Invalid Serial 
            tell front window's active tab to set checkIfSNIsCorrect to execute javascript "document.getElementsByClassName('subheader ng-binding')[0].innerHTML;"
            ## SN and device ID 

        end tell



        if theSearchstate is equal to "not ready" then
            delay 1


        else if checkIfSNIsCorrect contains serialNumber then
            set theSearchstate to "Completed"
            set checkIfSNIsCorrect to "SN is Correct"
            exit repeat

        else if checkIfSNIsInvalid contains "Serial Does Not Exists" then
            set theSearchstate to "invalid S/N"
            exit repeat

        else if checkIfSNIsInvalid contains "serviceErrorWhileSearching" then
            set theSearchstate to "Error with GCRM"
            exit repeat
        end if



    on error
        --
    end try
end repeat

return theSearchstate

However this is not working at all, I tried in different way, but I can't make it work.

Any suggestion ?

Aucun commentaire:

Enregistrer un commentaire