Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| applescript_conditionals [2010/06/02 16:11] – jay | applescript_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 **'' | ||
| + | |||
| + | * If the current time is between 8am and 10am OR between 4pm and 6pm | ||
| + | < | ||
| + | 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 | ||
| + | </ | ||
| + | * If a light named " | ||
| + | < | ||
| + | </ | ||
| + | * If a light named " | ||
| + | < | ||
| + | </ | ||
| + | * If the garage door is closed (with the I/O Linc Garage Door Kit) | ||
| + | < | ||
| + | -- 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 " | ||
| + | return item 1 of theList | ||
| + | </ | ||
| + | * If iCal is running | ||
| + | < | ||
| + | with timeout of 1 second | ||
| + | tell application " | ||
| + | if (get name of every process) contains " | ||
| + | return true | ||
| + | end if | ||
| + | end tell | ||
| + | end timeout | ||
| + | end try | ||
| + | return false | ||
| + | </ | ||
| + | * If the time is between 8am and 4pm AND the garage door is closed AND the variable " | ||
| + | < | ||
| + | if ((theCurrentHour ≥ 8) and (theCurrentHour < 16)) then | ||
| + | set theList to binary inputs of device " | ||
| + | if ((item 1 of theList) and (value of variable " | ||
| + | return true | ||
| + | end if | ||
| + | end if | ||
| + | return false | ||
| + | </ | ||
| + | * If a light named " | ||
| + | < | ||
| + | </ | ||