Easy...

I have been asking stupid questions lately – but this forum is AWESOME :smiley: :smiley: :smiley:

I am trying to make a security app that sees when my laptop is moving. My creation is suppost to have 2 different lists of numbers that tell me the tilt. I want to retrieve these numbers twice between a tenth of a second. Then If the current tilt is out of the range of those two numbers, an alarm sound will play. Understand?

I have a accelerometer utility that runs in Terminal and gets 3 numbers that help me get the tilt of my laptop. I can get those numbers in a list like this:

set thewords to words of (do shell script "/Users/dylanweber/AMSTracker") --change your path
set tilt to {item 6 of thewords as integer, item 7 of thewords as integer, last item of thewords as integer}

My problem is that how do I make a way to see if the number is in the range of those two. I so far have:

set numb to 0
set equal_ to false
repeat with i from 1 to 3
	if (item 1 of tilt) + 1 is not item 1 of tilt2 then
		set numb to numb + 1
		set equal_ to true
	end if
	if equal_ then
		exit repeat
	end if
end repeat

That DOESN’T WORK!

Do people understand?

How about something like this? I’ve just summed the three results to simplify the testing, but you get the idea.

property tracker : "~/Library/Scripts/SuddenMotion/AMSTracker/AMSTracker"
set Sum_1 to 0
set Sum_2 to 0

repeat until (Sum_2 - Sum_1) > 5 or (Sum_2 - Sum_1) < -5
	set Sum_1 to getSum()
	delay 0.1
	set Sum_2 to getSum()
end repeat

say "Tilt"

to getSum()
	set tSum to 0
	set Axes to words of paragraph 2 of (do shell script tracker)
	repeat with oneVal in Axes
		set tSum to tSum + (oneVal as integer)
	end repeat
	log tSum -- useful to see the results (Open that window with Option-Command L)
	return tSum
end getSum

Perfect.

property tracker : "~/AMSTracker"
set Sum_1 to 0
set Sum_2 to 0

display dialog "This is a tilt alarm. When your computer moves, an alarm with sound. Would you like to activate the alarm?" buttons {"Cancel", "Activate"} cancel button "Cancel" default button "Activate" with title "Activate?"

repeat until (Sum_2 - Sum_1) > 5 or (Sum_2 - Sum_1) < -5
	set Sum_1 to getSum()
	delay 0.1
	set Sum_2 to getSum()
end repeat
set vol to output volume of (get volume settings)
set volume 10
do shell script "afplay " & quoted form of POSIX path of ((path to resource "alarm.mp3" in bundle (path to me)) as string)
set volume vol
to getSum()
	set tSum to 0
	set Axes to words of paragraph 2 of (do shell script tracker)
	repeat with oneVal in Axes
		set tSum to tSum + (oneVal as integer)
	end repeat
	log tSum -- useful to see the results (Open that window with Option-Command L)
	return tSum
end getSum