Page 1 of 1

Conditions applescript with delay

PostPosted: Tue Apr 19, 2016 5:31 pm
by kidney
Can this be done, I 'm trying to have a condition applescript that would contains a delay before checking the next condition?


Code: Select all
if the value of variable "DSC_Zones_Activity" contains "Porte" then delay  75 and the value of variable "DSC_Status" contains "stay"
 then
   return true
else
   return false
end if


I know this doesn't work because I havent scripted in ages..... but i want to have a delay between checking both variable before returning a true value.

Re: Conditions applescript with delay

PostPosted: Tue Apr 19, 2016 6:00 pm
by peteinau
Hi,

A small tweak is all that is needed

if the value of variable "DSC_Zones_Activity" contains "Porte" then
delay 75
if value of variable "DSC_Status" contains "stay" then
return true
else
return false
end if
else
return false
end if

Re: Conditions applescript with delay

PostPosted: Thu Apr 21, 2016 7:27 pm
by kidney
This seem to make indigo crash, every time i try to change the delay it crashes indigo completely.

This is the condition script I wanna use....

Code: Select all
if the value of variable "DSC_Status" contains "stay" then
   delay 75
   if value of variable "DSC_Zones_Activity" contains "Porte" then
      return true
   else
      return false
   end if
else
   return false
end if

Re: Conditions applescript with delay

PostPosted: Thu Apr 21, 2016 8:00 pm
by ckeyes888
If you're running it within Indigo that would explain the lockup.
Anything with any real delay should be executed externally.

Carl

Re: Conditions applescript with delay

PostPosted: Thu Apr 21, 2016 9:46 pm
by gtreece
I'm not quite clear what you're attempting here, but the advice given is sound, for the question you asked. I use 'delay' statements in some of my applescripts, but only a delay 1 or a delay 2. Nothing like a delay 75, which Indigo will get unhappy waiting for.

Besides running your script externally rather than embedded, perhaps there's another way to accomplish what you're working on. Maybe start a timer device if 'DSC_Status' contains 'stay', and then trigger off the timer ending to do your next check.

Re: Conditions applescript with delay

PostPosted: Fri Apr 22, 2016 1:10 pm
by jay (support)
AppleScript conditions run embedded, and as with all embedded AppleScripts it has to run on the main server execution thread (AppleScript requires it). Because of that, any time you put a long delay in it it holds up all other processing until the script finishes.

You'll probably want to run your script as an external script action, and change the "return true" statements to execute an action group that contains all the actions you currently have in your trigger/schedule. Basically, move your conditional logic from the conditions to an action.

Re: Conditions applescript with delay

PostPosted: Sun Apr 24, 2016 6:52 am
by kidney
OK based on few recommandation i Have change my approach to what i'm trying to achieve....
I'll accomplish what i'm trying to do in the action script instead will be better that way.
Can a if then scenario be done in the action applescripts then?

Something like this which is probably full of mistake LOL ;(

Code: Select all
property connectionName : "DSC864"
if value of variable "DSC_Zones_Activity" contains "Porte" then
    tell application "Serial Bridge"
   send to source connectionName byte list {48, 51, 49, 49, 67, 53, 13, 10}
     end tell
else
    tell application "Serial Bridge"
   send to source connectionName byte list {48, 51, 48, 49, 67, 52, 13, 10}
    end tell
end if

Re: Conditions applescript with delay

PostPosted: Sun Apr 24, 2016 9:09 am
by jay (support)
I edited your script inline - I believe that will work.

Re: Conditions applescript with delay

PostPosted: Tue Apr 26, 2016 4:13 am
by kidney
Thanks, but it look like it doesn't take the if in consideration and sends the first command only

Re: Conditions applescript with delay

PostPosted: Tue Apr 26, 2016 9:36 am
by jay (support)
Hmmm, I just tried this and it works fine (I don't have Serial Bridge installed - btw I'm quite impressed it's still working for you):

Code: Select all
property connectionName : "DSC864"
tell application "IndigoServer"
   if value of variable "DSC_Zones_Activity" contains "Porte" then
      log "True path - variable value is: " & (value of variable "DSC_Zones_Activity")
      -- tell application "Serial Bridge"
      --send to source connectionName byte list {48, 51, 49, 49, 67, 53, 13, 10}
      --  end tell
   else
      log "False path - variable value is: " & (value of variable "DSC_Zones_Activity")
      -- tell application "Serial Bridge"
      --send to source connectionName byte list {48, 51, 48, 49, 67, 52, 13, 10}
      -- end tell
   end if
end tell