As alot of you probaly know, im making a alarm that is set when the laptop is moved (http://semaja2.ewales.info), but at the time of posting the server is down.
Anywho onto a serious note, i was wondering how you would use the user key in a applescript, like so when they goto disarm the alarm is uses the account that it was locked in to disarm it.
I ask this because my current solution just wont work no matter was it gives me errors if the key doesnt exist which is whats really screwed, and other problems.
Anyideas?
-- alarm.applescript
-- alarm
-- Created by Steven Halford on 08/04/2006.
-- Modified by semaja2 on 13/04/2006
-- Copyright 2006 Steven Halford. All rights reserved.
property appName : "MultiAlarm"
--machType is either powerbook or ibook
property machType : "powerbook"
property alarmActivated : "false"
property thisHere : ""
property theUpperX : ""
property theLowerX : ""
property theUpperY : ""
property theLowerY : ""
property get_password : "0"
property the_password : "Hello"
property new_password : ""
property theOldVolume : ""
property alarmVolumeAlert : "100"
property alarmVoice : false
property alarmGrowl : 0
--Sounds
property alert_snd : ""
to getPW(KeyName)
tell application "Keychain Scripting"
launch
tell current keychain to tell (some generic key whose name is KeyName) to set PWD to password
end tell
end getPW
on launched theObject
set alert_snd to load sound "caralarm.aiff"
--load sound "caralarm.aiff"
set theMachine to do shell script "/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/grep 'Machine Name' | /usr/bin/colrm 1 20"
if theMachine is not "" then
set {theModel} to getSystem(theMachine)
end if
if theModel contains "powerbook" then
--beep 1
set visible of window "about" to true
else if theModel contains "ibook" then
if machType contains "hirespb" then
set visible of window "nosupport" to true
--beep 10
else
--beep 1
set visible of window "about" to true
end if
else
set visible of window "nosupport" to true
--beep 10
end if
end launched
--on awake from nib theObject
--end awake from nib
--on will quit theObject
-- not sure if loaded sounds are saved on quit
-- no harm
-- delete alert_snd
--end will quit
on idle theObject
if alarmActivated is false then
end if
if alarmActivated is true then
repeat while alarmActivated is true
--runs motion cmd to find x and y axis
do shell script thisHere & "Contents/Resources/AMSTracker"
set theNewCoords to last paragraph of result
if theNewCoords is not "" then
set {theNewX, theNewY} to getXY(theNewCoords)
set theNewX to theNewX + 1000
set theNewY to theNewY + 1000
--Checks the x and y axis for change if change is found it will start the process
if theNewX is greater than theUpperX or theNewX is less than theLowerX or theNewY is greater than theUpperY or theNewY is less than theLowerY then
alarmAlert(1)
else
--stops sound and reactivates systems
--stop (load sound "caralarm.aiff")
set alarmGrowl to 0
end if
end if
end repeat
end if
end idle
---------------Interface Functions---------------
--Menu Items
on choose menu item theObject
set n to name of theObject
if n is "Arm" then
alarmActivate(1)
else if n is "Disarm" then
if alarmActivated is true then
set visible of window "main" to true
end if
end if
end choose menu item
--Text Fields
on end editing theObject
set n to name of theObject
if n is "secureDisarm" then
set c to content of text field "secureDisarm" of window "main"
set the_password to c
set the content of text field "secureDisarm" of window "main" to ""
if the_password = getPW("MultiAlarm") then
set visible of window "main" to false
alarmDeactivate(1)
else
--display dialog "Incorrect Password"
beep 2
end if
--beep 2
else if n is "secureExit" then
set c to content of text field "secureExit" of window "quitCheck"
set the_password to c
set the content of text field "secureExit" of window "quitCheck" to ""
if the_password = getPW("MultiAlarm") then
quit
else
--display dialog "Incorrect Password"
beep 2
end if
--beep 2
else if n is "secureOld" then
set c to content of text field "secureOld" of window "setCheck"
set the_password to c
set the content of text field "secureOld" of window "setCheck" to ""
if the_password = getPW("MultiAlarm") then
set visible of window "setpass" to true
set visible of window "setCheck" to false
else
--display dialog "Incorrect Password"
beep 2
end if
--beep 2
else if n is "secureSet" then
set the_password to content of text field "secureSet" of window "setpass"
set visible of window "setpass" to false
keychain(the_password)
--beep 1
end if
end end editing
--Clicked objects
on clicked theObject
set n to name of theObject
if n is "Disarm" then
set c to content of text field "secureDisarm" of window "main"
set the_password to c
set the content of text field "secureDisarm" of window "main" to ""
if the_password = getPW("MultiAlarm") then
set visible of window "main" to false
alarmDeactivate(1)
else
--display dialog "Incorrect Password"
beep 2
end if
--beep 2
else if n is "Confirm" then
set c to content of text field "secureOld" of window "setCheck"
set the_password to c
set the content of text field "secureOld" of window "setCheck" to ""
if the_password = getPW("MultiAlarm") then
set visible of window "setpass" to true
set visible of window "setCheck" to false
else
--display dialog "Incorrect Password"
beep 2
end if
--Exit System
else if n is "exit" then
set c to content of text field "secureExit" of window "quitCheck"
set the_password to c
set the content of text field "secureExit" of window "quitCheck" to ""
if the_password = getPW("MultiAlarm") then
quit
else
--display dialog "Incorrect Password"
beep 2
end if
--beep 2
else if n is "Enable Alarm" then
alarmActivate(1)
else if n is "Disarm Alarm" then
set x to count (every sound)
say x
if alarmActivated is true then
set visible of window "main" to true
end if
else if n is "Set" then
set newPWD to content of text field "secureSet" of window "setpass"
keychain(newPWD)
set visible of window "setpass" to false
--beep 1
else if n is "voice" then
if alarmVoice is true then
set alarmVoice to false
else if alarmVoice is false then
set alarmVoice to true
end if
end if
end clicked
----------------Functions------------
--Gets and organises coordinates
on getXY(theCoords)
set oldTID to AppleScript's text item delimiters
set text item delimiters to {" "}
set theX to second text item of theCoords
set theY to third text item of theCoords
set text item delimiters to oldTID
return {theX, theY}
end getXY
--gets machine name
on getSystem(theMachine)
set oldTID to AppleScript's text item delimiters
set text item delimiters to {" "}
set theName to first text item of theMachine
set text item delimiters to oldTID
return {theName}
end getSystem
--Checks and controls growl
on GrowlNotify(myName, myTitle, myText)
set myApp to ""
tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
if GrowlRunning ≥ 1 then
try
set myApp to "GrowlHelperApp"
set notifs to "{\"Alarm Activated\", \"Alarm Deactivated\",\"Theft in progress\"}"
tell application myApp to run script "register as application \"" & appName & "\" all notifications " & notifs & " default notifications " & notifs & " icon of application \"" & appName & "\""
tell application myApp to run script "notify with name \"" & myName & "\" title \"" & myTitle & "\" application name \"" & appName & "\" description \"" & myText & "\" icon of application \"" & appName & "\""
end try
end if
end GrowlNotify
on keychain(newPWD)
tell application "Keychain Scripting"
tell keychain 1
unlock -- gotta unlock it.
--set theKey to (first key whose name is "Some Key") -- then find it
set password of (first generic key whose name is "MultiAlarm") to newPWD
end tell
end tell
end keychain
---------------------Alarm Functions---------------------
--Alarm Activation Script
on alarmActivate(do)
set theOldVolume to get output volume of (get volume settings)
set alarmActivated to true
---------------Sets paths---------------------
set thisHere to path to me
set thisHere to POSIX path of thisHere
--------------Sound Configs-----------------
--Sets the sound for alarm activation
set theArming to load sound "armx2.wav"
--------------------------------------------------
--set alarmVolumeOrignal to volume
--plays the arming sound
--beep
play theArming
--runs motion cmd to find x and y axis
do shell script thisHere & "Contents/Resources/AMSTracker"
set theCoords to last paragraph of result
if theCoords is not "" then
set {theX, theY} to getXY(theCoords)
set theUpperX to theX + 1002
set theLowerX to theX + 998
set theUpperY to theY + 1002
set theLowerY to theY + 998
end if
GrowlNotify("Alarm Activated", "Alarm", "Warning : Alarm Primed")
end alarmActivate
--Alarm Deactivation Script
on alarmDeactivate(do)
--Deactivates the check
set alarmActivated to false
--plays the arming sound
--beep 2
play (load sound "arm.wav")
--Displays growl notification
GrowlNotify("Alarm Deactivated", "Alarm", "Warning : Alarm Disarmed")
set volume output volume theOldVolume
end alarmDeactivate
on alarmAlert(do)
--Play alarm sound
play alert_snd
--Say
if alarmVoice is true then
say "Help! I am being stolen."
end if
--beep 1
--Set the volume to MAX
set volume alarmVolumeAlert
--Displays Growl Notification
if alarmGrowl is equal to 0 then
set alarmGrowl to 1
GrowlNotify("Theft in progress", "Alarm", "Warning : Theft in progress")
end if
return
end alarmAlert
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)