Dialog

yeh i cleaned the targets, but i think my nib file was corrupt or something, but now when i created a new nib it just wont do anything, the program will launch but not run the on launch theObject. is there something i have to set for the nib file to work :S

edit: forgot to enable the applescript connections :stuck_out_tongue:

ok well i dont know how to explain this since you wont look at the picture i posted but here goes, i have a window called main, it has a picture of the app, then it has text saying please eneter your password to disarm, below that it has a text field named secure and under that is a button called disarm

now i tried putting your code in to my script as you can see below but it wont work, when i run it i get this error :

-- 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 : ""
property thisHere : ""
property theUpperX : ""
property theLowerX : ""
property theUpperY : ""
property theLowerY : ""
property get_password : false
property the_password : "password"




on launched theObject
	
	
	alarmActivate(1)
	
end launched

on idle theObject
	if get_password is true then
		set visible of window "main" to true
		set get_password to false
	end if
	--runs motion cmd to find x and y axis
	set theNewCoords to do shell script thisHere & "Contents/Resources/motion " & machType
	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)
			set get_password to true
		else
			--stops sound and reactivates systems
			stop (load sound "caralarm.aiff")
			set alarmActivated to "0"
			
		end if
	end if
end idle

on choose menu item theObject
	set n to name of theObject
	if n is "Disarm Alarm" then
		set get_password to true
	else if n is "stop" then
		set get_password to false
	end if
end choose menu item

on end editing theObject
	set c to content of text field "secure" of window "main"
	if c is the_password then
		set visible of window "main" to false
		quit
	end if
end end editing




on getXY(theCoords)
	set oldTID to AppleScript's text item delimiters
	set text item delimiters to {" "}
	set theX to first text item of theCoords
	set theY to second text item of theCoords
	set text item delimiters to oldTID
	return {theX, theY}
end getXY

on getSystem(theMachine)
	set oldTID to AppleScript's text item delimiters
	set text item delimiters to {" "}
	set theModel to first text item of theMachine
	set text item delimiters to oldTID
	return {theModel}
end getSystem

on smsSystem(theCMD)
	set oldTID to AppleScript's text item delimiters
	set text item delimiters to {" "}
	set smsState to first text item of theCMD
	set text item delimiters to oldTID
	return {smsState}
end smsSystem



--Alarm Activation Script
on alarmActivate(do)
	
	---------------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"
	--------------------------------------------------
	
	--plays the arming sound
	beep
	play theArming
	
	--runs motion cmd to find x and y axis
	set theCoords to do shell script thisHere & "Contents/Resources/motion " & machType
	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

on alarmAlert(do)
	--Play alarm sound
	play (load sound "caralarm.aiff")
	--Say
	say "Help! I am being stolen."
	beep
	--Checks if growl has already been activated
	if alarmActivated is less than 1 then
		--Set the volume to MAX
		--set volume 100
		set alarmActivated to "1"
		GrowlNotify("Theft in progress", "Alarm", "Warning : Theft in progress")
	end if
	return
	
	
end alarmAlert

--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 Deactived\",\"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


BUMP^

Ive been playing around with this trying to make it for for like 4 hours now, someones got to know how to work this

Hi semaja2,

I’m having a hard time trying to find what’s wrong in your script. Maybe it’s too long. You might want to try just making the password part work in a new project first. That’s what I do, break apart a script into smaller simpler pieces. It’s easier to find what’s wrong.

gl,

ok i followed your advice onto make it into smaller pieces first but i still get the same error, now thats using the idetical code nothing changed from your post, could it have something to do with the interface builder cuz i think i copied down exactly what was needed.

PS could you email the archive of the project including the nib to semaja2 (at) gmail.com

Hi semaja2,

Sorry, but I don’t give out my address.

I don’t know if you can post this with the AppleScript tags, but here it is again.


property get_password : false
property the_password : "password"

on idle theObject
	if get_password then
		set visible of window "main" to true
		set get_password to false
	end if
	beep 1
	return 2
end idle

on choose menu item theObject
	set n to name of theObject
	if n is "go" then
		set get_password to true
	else if n is "stop" then
		set get_password to false
	end if
end choose menu item

on end editing theObject
	set c to contents of text field "secure" of window "main"
	if c is the_password then
		set visible of window "main" to false
		quit
	end if
end end editing

I went over it several times and it’s working perfectly, so I don’t know what’s wrong on your end. I made one change. Replaced ‘content’ with ‘contents’ in this line:

set c to contents of text field “secure” of window “main”

That’s the only thing I could see that might cause problems although it shouldn’t. I tried to duplicate your error by making changes in the interface, but couldn’t get that error. Tried to put in bad names, checked out your variables, and some other things, but still couldn’t duplicate your error. The only thing I am thinking is that, you must be doing something wrong in Interface Builder, like not naming things right, not using a text field, etc.

gl,

well i have a somewhat working code now, i went to the basics, removed the gui and just used the meun, so i have a menu with just this now :

Alarm
Disarm
Arm

so when they are pressed they set a variable to start and disarm the alarm, now once i work out the bugs ill try adding the password dialog again and hopefully it should work

PS. thank guys for your great support, ive added a link to your site on my site under partners

Hi semaja2,

I don’t know what happened to my other post, so here it is again.

I couldn’t find anything wrong with this and it works perfectly for me.


property get_password : false
property the_password : "password"

on idle theObject
	if get_password then
		set visible of window "main" to true
		set get_password to false
	end if
	beep 1
	return 2
end idle

on choose menu item theObject
	set n to name of theObject
	if n is "go" then
		set get_password to true
	else if n is "stop" then
		set get_password to false
	end if
end choose menu item

on end editing theObject
	set c to contents of text field "secure" of window "main"
	if c is the_password then
		set visible of window "main" to false
		quit
	end if
end end editing

I looked at all kinds of things in your script, but couldn’t find anything. In this script I tried to all types of things to duplicate your error, but nothing was found. Maybe it’s the copying of the script, so I placed it in the AppleScript tags. One thing I changed is ‘content’ to ‘contents’ in this line:

set c to contents of text field “secure” of window “main”

and added the ‘quit’ command, but these things shouldn’t matter. This should be simple, so I don’t know what’s going on on your end.

I don’t understand how it could error right away. At the beginning the variable get_password is false, so the only thing the application should be doing is beeping every 2 seconds. Maybe get rid of the beep?

There’s only the window and the text field (and the menu wihich does nothing until you click it). In fact even the window isn’t visible, until you click the menu item “go”.

gl,

ok thanks for your help i got it to work great now, ill add the keychain in later. i only have one problem, when the alarm is activated or going off it is near impossible to use the GUI to enter passwords or just press the disable button

kel: i wont bother uploading the nib since you wont use it anyway :P, but your name has been added into the thankyous

-- 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 : false
property the_password : ""

on launched theObject
	
	beep 1
	
end launched

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
			set theNewCoords to do shell script thisHere & "Contents/Resources/motion " & machType
			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 alarmActivated to false
					
				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)
	end if
end choose menu item

--Text Fields

on end editing theObject
	set c to content of text field "secure" of window "main"
	if c is the_password then
		set visible of window "main" to false
		alarmDeactivate(1)
		beep 2
	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 "secure" of window "main"
		if c is the_password then
			set visible of window "main" to false
			alarmDeactivate(1)
			beep 1
		end if
	else if n is "Enable Alarm" then
		alarmActivate(1)
	else if n is "Disable Alarm" then
		alarmDeactivate(1)
	else if n is "Set" then
		set the_password to content of text field "secure" of window "setpass"
		set visible of window "main" to false
		display dialog "Password Set"
		set visible of window "main" to false
		beep 1
	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 first text item of theCoords
	set theY to second text item of theCoords
	set text item delimiters to oldTID
	return {theX, theY}
end getXY

--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

---------------------Alarm Functions---------------------

--Alarm Activation Script
on alarmActivate(do)
	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"
	--------------------------------------------------
	
	--plays the arming sound
	beep
	play theArming
	
	--runs motion cmd to find x and y axis
	set theCoords to do shell script thisHere & "Contents/Resources/motion " & machType
	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")
	
end alarmDeactivate


on alarmAlert(do)
	--Play alarm sound
	play (load sound "caralarm.aiff")
	--Say
	say "Help! I am being stolen."
	beep 1
	--Checks if growl has already been activated -- DOESNT WORK
	if alarmActivated is true then
		--Set the volume to MAX
		set volume 100
		--set alarmActivated to "1" --- REMOVED
		--Displays Growl Notification
		GrowlNotify("Theft in progress", "Alarm", "Warning : Theft in progress")
	end if
	return
	
	
end alarmAlert

Hi semaja2,

Alright! I can’t believe it. :smiley:

You might want to post your alarm question in the AppleScript Studio section.

gl,

ok well besides from that, a few more questions :stuck_out_tongue:

How do i add stuff to the dock menu when u right click on the icon?

How would i restore the volume after the alarm is disabled?

also im having troubles implementing a key in the keychain

now the problem is it keeps saying that the key chain exists, but how do i change the password, and if the key doesnt exist it creates a new key

to setPW(KeyName, newPWD)
	tell application "Keychain Scripting"
		launch
		try
			tell current keychain to tell (some generic key whose name is KeyName) to set password to newPWD
		on error
			make new generic key with properties {name:"MultiAlarm", account:"MultiAlarm", password:newPWD}
			tell current keychain to tell (some generic key whose name is KeyName) to set password to newPWD
		end try
	end tell
	return 2
end setPW

You’re nearly there:

set {text:thePassword} to text returned of (display dialog "Enter new
password" default answer "" with hidden answer) as string
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 "ASPW") to thePassword
	end tell
end tell

what does that do if the key doesnt exist, also ive built a interface for the password so i didnt need that, also whats with the unlocking

Creates the key (try it as a separate script, it does for me). It will ask for your password to unlock. If you look at the Keychain Access app. you’ll see a lock in the top left corner. That’s what you’re unlocking. If it is unlocked, nothing happens.

im using xcode for this but i get this error

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