Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
applescript_conditionals [2010/06/02 16:10] jayapplescript_conditionals [2026/04/07 18:27] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== Example Condition AppleScripts ======
 +This How-To will show several common and useful AppleScript Condition scripts. Most will run correctly if you just paste them in to the "If script returns true" text field in the **''Conditions''** tab.
 +
 +  * If the current time is between 8am and 10am OR between 4pm and 6pm
 +<code>-- Get the current hour
 +set theCurrentHour to hours of (current date)
 +
 +-- compare it to see if it's in one of our ranges - between 8am
 +-- and 10am OR between 4pm and 6pm
 +--
 +-- Note, the number that is stored in theCurrentHour will be 0-23
 +if (((theCurrentHour ≥ 8) and (theCurrentHour < 10)) or ¬
 + ((theCurrentHour ≥ 16) and (theCurrentHour < 18))) then
 + return true
 +end if
 +return false
 +</code>
 +  * If a light named "Office Lamp" is ON
 +<code>return (on state of device "Office Lamp")
 +</code>
 +  * If a light named "Office Lamp" is OFF
 +<code>return not (on state of device "Office Lamp")
 +</code>
 +  * If the garage door is closed (with the I/O Linc Garage Door Kit)
 +<code>-- I/O devices can have multiple inputs, so you have to get
 +-- the list of inputs first. For the I/O link, it only 
 +-- has one, so we just look at the first one in the
 +-- list.
 +set theList to binary inputs of device "Garage Door"
 +return item 1 of theList
 +</code>
 +  * If iCal is running
 +<code>try
 + with timeout of 1 second
 + tell application "System Events"
 + if (get name of every process) contains "iCal" then
 + return true
 + end if
 + end tell
 + end timeout
 +end try
 +return false 
 +</code>
 +  * If the time is between 8am and 4pm AND the garage door is closed AND the variable "alarmStatus" is set to "away"
 +<code>set theCurrentHour to hours of (current date)
 +if ((theCurrentHour ≥ 8) and (theCurrentHour < 16)) then
 + set theList to binary inputs of device "Garage Door"
 + if ((item 1 of theList) and (value of variable "alarmStatus" = "away")) then
 + return true
 + end if
 +end if
 +return false
 +</code>
 +  * If a light named "Office Lamp" is OFF and it's dark outside
 +<code>return (not (on state of device "Office Lamp") and (value of variable "isDaylight" = "false"))
 +</code>