What's wrong with my applescript

When I try to run my Applescript Application in Xcode, it opens 2 apps. One quits immediately the other quits after a while. It is one of my first applications so I’m really a noob. This is my code.

on awake from nib theObject
	using terms from application "Things"
		tell application "Things"
			activate
			set myList to {} -- list met alle to do s opstellen
			set myCount to 1
			repeat (count every to do of list "Next") times
				set beginning of myList to name of to do myCount of list "Next"
				set myCount to myCount + 1
			end repeat
		end tell
	end using terms from
	
	set contents of table view 1 of scroll view 1 of window 1 to myList -- list naar table 
end awake from nib

on clicked theObject
	if name of theObject is "OKbutton" then
		set myToDo to contents of data cell 1 of selected data row of table view 1 of scroll view 1 of window 1 -- zet naam in variabele
		
		using terms from application "Things"
			tell application "Things" to tell list "next" to tell to do myToDo -- naam, datum, tags & notes in variabele zetten
				set myName to name as string
				set myDate to creation date as string
				set myTags to tag names as string
				set myNotes to notes as string
			end tell
		end using terms from
		
		-- text fields in zetten
		set contents of text field "teName" of window 1 to myName
		set contents of text field "teDate" of window 1 to myDate
		set contents of text field "teTags" of window 1 to myTags
		set contents of text field "teNotes" of window 1 to myNotes
	end if
end clicked

on should quit after last window closed theObject
	quit
end should quit after last window closed

it takes information of the app “Things” and displays it in a nice Graphical Interface. But my app doesn’t want to start. So pleas help

Thanx,
ief2

PS: Sorry for my bad english. I live in Belgium, speak dutch and I just try to make a couple of good sentences

Model: iMac G5
Browser: Safari 531.9
Operating System: Mac OS X (10.5)

Hi,

welcome to MacScripter.

The return value of the on should quit after last window closed handler must be an boolean value.
True does quit the app after the last window closed, false does not


on should quit after last window closed theObject
   return true
end should quit after last window closed

Nothing has changed, the same events keep happening

I really am desperate

have you connected the awake from nib handler in Interface Builder?
To check whether the handler is called, add this line inside the awake form nib hander

log "awake from nib"

and open the console (⇧⌘R)

by the way: The using terms from blocks are not necessary

Edit:

this part

using terms from application "Things"
	tell application "Things"
		activate
		set myList to {} -- list met alle to do s opstellen
		set myCount to 1
		repeat (count every to do of list "Next") times
			set beginning of myList to name of to do myCount of list "Next"
			set myCount to myCount + 1
		end repeat
	end tell
end using terms from

does the same as

tell application "Things" to set theList to reverse of (get name of to dos of list "Next")

it’s also not necessary to activate Things

Thanx for the reply: you see, I’m just a noob.

my Console gives me this

your app just crashes :slight_smile:


 set contents of table view 1 of scroll view 1 of window 1 to myList

to avoid problems it’s recommended to name each UI element.
In Interface Builder name the window and the table view (including scroll view) in the AppleScript tab of the inspector and then use this reference e.g


 set contents of table view "tableView" of scroll view "scrollView" of window "main" to myList

Doesn’t change anything :frowning:

can have several reasons, I guess still bad referencing

Well, because you say it could be anything i’ve posted my app on a hosting site: click

it’s the Project folder. I really hope you can help me

PS: link: http://aghyour.com/verzenden/download.php?file=a4497c80f63cf5b94629413e60d01d21

There were a few problems.

¢ You had a second script with a similar name, and some UI elements were connected to that script.
¢ The problem which caused the crash was the action button which was connected to an event handler but no script was selected.

In the AppleScript tab of the inspector you must always select a script if you connect any event handler.
But if no event handler is connected for the specified UI element, there’s no need to select a script.

Consider that many UI elements have multiple layers e.g. scroll view > table view > cell.
Check always the window title of the inspector to have chosen the proper element

Here’s your project
http://www.klieme.ch/pub/To Do Checker.zip

the link must be probably percent escaped, maybe

http://www.klieme.ch/pub/To%20Do%20Checker.zip

i always avoid space characters in file names :wink:

Thanx for fixing my app.

I will think about your advices

I just have one more question, why is my on quit handler not working?

-- To Do Checker.applescript
-- To Do Checker

--  Created by ief2 on 8/09/09.
--  Copyright 2009 __MyCompanyName__. All rights reserved.
on awake from nib theObject
	log "awake from nib"
	tell application "Things" to set myList to reverse of (get name of to dos of list "Next")
	set contents of table view "tTable" of scroll view "ScrollView" of window "Main" to myList -- list naar table 
end awake from nib

on clicked theObject
	if name of theObject is "OKbutton" then
		set myToDo to contents of data cell 1 of selected data row of table view "tTable" of scroll view "ScrollView" of window "Main" -- zet naam in variabele
		
		tell application "Things" to tell list "next" to tell to do myToDo -- naam, datum, tags & notes in variabele zetten
			set myName to name as string
			set myDate to creation date as string
			set myTags to tag names as string
			set myNotes to notes as string
		end tell
		-- text fields in zetten
		set contents of text field "teName" of window 1 to myName
		set contents of text field "teDate" of window 1 to myDate
		set contents of text field "teTags" of window 1 to myTags
		set contents of text field "teNotes" of window 1 to myNotes
	end if
	
	if name of theObject is "OpenButton" then
		tell application "Things" to tell window "things" to activate
	end if
end clicked

on quit
	tell application "Things" to quit
	continue quit
end quit

on should quit after last window closed theObject
	return true
end should quit after last window closed

better use the will quit handler connected from File’s Owner