Hi. Here is a script I am working on. I need some help with passing a variable’s value as a parameter of a tell. Look for HELP at middle. Thanks so much.
set today to current date
set currentTimeSeconds to time of today
if (currentTimeSeconds > 22000) and (currentTimeSeconds < 63000) then
set thePresets to {“preset1”, “preset2”, “preset3”, “preset4”, “preset5”, “preset6”, “preset7”, “preset8”}
set theCurrentPreset to “preset5”
repeat with theCurrentPreset in thePresets
tell application “SecuritySpy”
if ((get motion camera number 2) < 10) then
delay 2
if ((get motion camera number 2) < 10) then
set sensitivity 0 camera number 2
ptz (theCurrentPreset) camera number 2 // HELP- How do I properly pass theCurrentPreset to this SecuritySpy tell?
delay 9
set sensitivity 45 camera number 2
delay 1
end if
end if
end tell
end repeat
end if
Browser: Safari 537.71
Operating System: Mac OS X (10.8)
ptz preset1 camera number 2 // HELP- How do I properly pass theCurrentPreset to this SecuritySpy tell?
That is an Applescript “command” supported by SecuritySpy.app. I have verified it works outside of the repeat while loop I am trying to implement. I want to loop through preset1-preset8. This moves a Pan-Tilt-Zoom IP camera if little motion is at the present location.
SecuritySpy got an error:Can't make some data into the expected type.
That same line is highlighted. Back in the day, I could do this no problem in PHP, but this is for fun and after hours of trying many things, I’m tired so I’m asking for help.
ptz‚v : Execute a PTZ command
ptz left/Œright/Œup/Œdown/Œzoomin/Œzoomout/Œhome/Œupleft/Œupright/Œdownleft/Œdownright/Œpreset1/Œpreset2/Œpreset3/Œpreset4/Œpreset5/Œpreset6/Œpreset7/Œpreset8/Œsavepreset1/Œsavepreset2/Œsavepreset3/Œsavepreset4/Œsavepreset5/Œsavepreset6/Œsavepreset7/Œsavepreset8 : The movement type
[camera number integer] : The camera number
[camera name text] : The camera name
I have been unable to get the command to work at all with camera name.
Interesting. No errors but execution stops immediately.
set today to current date
set currentTimeSeconds to time of today
if (currentTimeSeconds > 22000) and (currentTimeSeconds > 63000) then
set thePresets to {preset1, preset2, preset3, preset4, preset5, preset6, preset7, preset8}
repeat with theCurrentPreset in thePresets
tell application "SecuritySpy"
if ((get motion camera number 2) < 10) then
set sensitivity 0 camera number 2
ptz (contents of theCurrentPreset) camera number 2
delay 9
set sensitivity 45 camera number 2
delay 1
end if
end tell
end repeat
end if
Oops, but of course. I had hope this time, but it compiled with no errors, then no execution, and no camera action. Until tomorrow…
set today to current date
set currentTimeSeconds to time of today
if (currentTimeSeconds > 22000) and (currentTimeSeconds < 63000) then
tell application "SecuritySpy"
set thePresets to {preset1, preset2, preset3, preset4, preset5, preset6, preset7, preset8}
repeat with theCurrentPreset in thePresets
if ((get motion camera number 2) < 10) then
set sensitivity 0 camera number 2
ptz (the contents of theCurrentPreset) camera number 2
delay 9
set sensitivity 45 camera number 2
delay 1
end if
end repeat
end tell
end if
Calculating from the time of your post as shown in the UK and the time zone offset in your profile, you posted the above at 21:28:51 your time. The ‘if’ line at the top of the script limits its operation to between 06:06:41 and 17:29:59 inclusively, so it won’t have been working for about four hours up to the time of your post.
Good catch, though I had recognized that, so I just flipped whichever comparison operator to make that if true. Just for good measure, I even tried it without it. That if is part of v1 (currently operational). This bit I need help with is for v2, the rest is “working” fluff.
SOLVED:
What do you know? A little sleep and what I tried last night does work, without the fluff, so I will have to realign that to do what I want.
tell application "SecuritySpy"
set thePresets to {preset1, preset2, preset3, preset4, preset5, preset6, preset7, preset8}
repeat with theCurrentPreset in thePresets
if ((get motion camera number 2) < 10) then
set sensitivity 0 camera number 2
ptz (the contents of theCurrentPreset) camera number 2
delay 9
set sensitivity 45 camera number 2
delay 1
end if
end repeat
end tell
Thank you all so much! I will keep posting as I make new changes so that you might advise me of a better way…
I made the if into a repeat until, and I edited a dumb mistake out of this post.
set today to current date
set currentTimeSeconds to time of today
repeat while (currentTimeSeconds > 22000) and (currentTimeSeconds < 63000)
tell application "SecuritySpy"
set thePresets to {preset1, preset2, preset3, preset4, preset5, preset6, preset7, preset8, preset6, preset4, preset2, preset1, preset3, preset5, preset7, preset8, preset7, preset6, preset5, preset4, preset3, preset2}
repeat with theCurrentPreset in thePresets
repeat until ((get motion camera number 2) < 40)
end repeat
set sensitivity 9 camera number 2
ptz (the contents of theCurrentPreset) camera number 2
delay 1
set sensitivity 55 camera number 2
delay 3
end repeat
end tell
end repeat
I had considered that…thanks for the heads up. I had to duplicate those 2 lines inside the repeat as the repeat itself uses currentTimeSeconds.
Attached is the “final” v2 with refined fluff added. The script will be an app running at boot from my Login Items. On my mind the only remaining thing I can think of is for the script to quit gracefully upon shutdown of the Mac. I currently have to press command-. to close the script app when I restart. I think it may close on it’s own eventually but when I say restart it should exit now.
-- Customized Automatic Patrol Script v2 --
repeat
set today to current date
set currentTimeSeconds to time of today
set firstRun to true
set isDark to false
repeat while (currentTimeSeconds > 22000) and (currentTimeSeconds < 63000)
tell application "SecuritySpy"
set isDark to false
set today to current date
set currentTimeSeconds to time of today
set thePresets to {preset1, preset2, preset3, preset4, preset5, preset6, preset7, preset8, preset6, preset4, preset2, preset1, preset3, preset5, preset7, preset8, preset7, preset6, preset5, preset4, preset3, preset2, preset4, preset6, preset8, preset7, preset5, preset3}
repeat with theCurrentPreset in thePresets
repeat until ((get motion camera number 2) < 30)
delay 1
end repeat
if firstRun is true then
set firstRun to false
set sensitivity 9 camera number 2
end if
ptz (the contents of theCurrentPreset) camera number 2
set sensitivity 55 camera number 2
delay 3
end repeat
end tell
end repeat
repeat while (isDark is false) and [(currentTimeSeconds > 63000) or (currentTimeSeconds < 22000)]
set isDark to true
set today to current date
set currentTimeSeconds to time of today
tell application "SecuritySpy"
set sensitivity 9 camera number 2
ptz preset3 camera number 2
delay 2
set sensitivity 65 camera number 2
end tell
end repeat
end repeat
When this is run as an app from Login Items, it cancels a restart. How can I make it quit nicely for a restart?
-- Customized Automatic Patrol Script v3 --
tell application "SecuritySpy"
set daySensitivity to 60
set nightSensitivity to 65
set motionThreshold to 45 -- set camera's threshold for move
set darkSeconds to 61000
set dawnSeconds to 22000
set runOnceAtDark to true
set runOnceAtDawn to true
set darkFlip to false
repeat
set today to current date
set currentTimeSeconds to time of today
-- Dark Section
repeat while currentTimeSeconds > darkSeconds or currentTimeSeconds < dawnSeconds -- * while dark, keep darkFlip true
set today to current date
set currentTimeSeconds to time of today
if runOnceAtDark is true then -- go to preset1 once at dark
set runOnceAtDark to false
set sensitivity 9 camera number 2
ptz preset1 camera number 2
delay 1
set sensitivity nightSensitivity camera number 2
end if
end repeat -- * End Dark
-- Daylight Patrol Section
repeat while currentTimeSeconds < darkSeconds and currentTimeSeconds > dawnSeconds -- * while light, patrol
set today to current date
set currentTimeSeconds to time of today
set thePresets to {preset1, preset2, preset3, preset4, preset5, preset6, preset7, preset8, preset6, preset4, preset2, preset1, preset3, preset5, preset7, preset8, preset7, preset6, preset5, preset4, preset3, preset2, preset4, preset6, preset8, preset7, preset5, preset3}
if runOnceAtDawn is true then
set runOnceAtDawn to false
set sensitivity 9 camera number 2
ptz preset1 camera number 2
delay 9
set sensitivity daySensitivity camera number 2
end if
repeat with theCurrentPreset in thePresets -- * loop through above list
set avgMotion to (get motion camera number 2)
repeat until avgMotion < motionThreshold -- if motion, keep delaying
set motionOne to (get motion camera number 2)
delay 1
set motionTwo to (get motion camera number 2)
set avgMotion to ((motionOne + motionTwo) / 2)
end repeat
ptz (the contents of theCurrentPreset) camera number 2 -- patrol to theCurrentPreset
delay 3
end repeat
end repeat -- End Daylight
end repeat
end tell