Conditions applescript with delay

Posted on
Tue Apr 19, 2016 5:31 pm
kidney offline
Posts: 199
Joined: Jul 15, 2007

Conditions applescript with delay

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.

Posted on
Tue Apr 19, 2016 6:00 pm
peteinau offline
Posts: 65
Joined: Jan 10, 2015

Re: Conditions applescript with delay

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

Posted on
Thu Apr 21, 2016 7:27 pm
kidney offline
Posts: 199
Joined: Jul 15, 2007

Re: Conditions applescript with delay

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

Posted on
Thu Apr 21, 2016 8:00 pm
ckeyes888 offline
Posts: 2024
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Conditions applescript with delay

If you're running it within Indigo that would explain the lockup.
Anything with any real delay should be executed externally.

Carl

Posted on
Thu Apr 21, 2016 9:46 pm
gtreece offline
Posts: 169
Joined: Sep 26, 2011

Re: Conditions applescript with delay

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.

Posted on
Fri Apr 22, 2016 1:10 pm
jay (support) offline
Site Admin
User avatar
Posts: 14534
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Conditions applescript with delay

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Apr 24, 2016 6:52 am
kidney offline
Posts: 199
Joined: Jul 15, 2007

Re: Conditions applescript with delay

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

Posted on
Sun Apr 24, 2016 9:09 am
jay (support) offline
Site Admin
User avatar
Posts: 14534
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Conditions applescript with delay

I edited your script inline - I believe that will work.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Apr 26, 2016 4:13 am
kidney offline
Posts: 199
Joined: Jul 15, 2007

Re: Conditions applescript with delay

Thanks, but it look like it doesn't take the if in consideration and sends the first command only

Posted on
Tue Apr 26, 2016 9:36 am
jay (support) offline
Site Admin
User avatar
Posts: 14534
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Conditions applescript with delay

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

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests