NSSlider...

Doing some tests to learn how NSSlider works…

I have got the slider to work to display numbers between 0 - 100 in NSTextfield.
But every time I close the window Script Editor quits… (crash)

But I couldn’t find what is wrong…

Anyone like to take a look.

use framework "Foundation"
use framework "AppKit"
use scripting additions

property arguments : missing value
property theTextField1 : missing value
property theTextField2 : missing value

on run
	try
		if my NSThread's isMainThread() as boolean then
			my performDialog:arguments
		else
			my performSelectorOnMainThread:"performDialog:" withObject:arguments waitUntilDone:true
		end if
	end try
end run

on performDialog:arguments
	set theButton to createButtonWithRect("OK", 30, 30, 60, 60, "buttonAction:")
	set theTextField1 to createTextFieldWithRect(20, 100, 100, 20)
	theTextField1's setPlaceholderString:"Type some text..."
	set theTextField2 to createTextFieldWithRect(150, 100, 100, 20)
	theTextField1's setPlaceholderString:"Slider values..."
	set theSlider to createSlider(50, 0, 100, "sliderAction:")
	set theView to createView(0, 0, 250, 300, {theButton, theTextField1, theTextField2, theSlider})
	set theWindow to createWindowWithRectAndSubview({theView}, 0, 0, 600, 400)
	theWindow's |center|()
	theWindow's makeKeyAndOrderFront:true
end performDialog:

on buttonAction:sender
	set theString to theTextField1's stringValue() as string
	display dialog theString
end buttonAction:

on sliderAction:sender
	set theNumber to sender's stringValue() as string
	theTextField2's setStringValue:theNumber
end sliderAction:

on createButtonWithRect(title, x, y, width, height, selector)
	set buttonSize to current application's NSMakeRect(x, y, width, height)
	set theButton to current application's NSButton's alloc()'s initWithFrame:buttonSize
	theButton's setTitle:title
	theButton's setAction:selector
	theButton's setTarget:me
	return theButton
end createButtonWithRect

on createTextFieldWithRect(x, y, width, height)
	set textFieldSize to current application's NSMakeRect(x, y, width, height)
	set theTextField to current application's NSTextField's alloc()'s initWithFrame:textFieldSize
	return theTextField
end createTextFieldWithRect

on createSlider(sliderValue, minValue, maxValue, selector)
	set theSlider to current application's NSSlider's sliderWithValue:sliderValue minValue:minValue maxValue:maxValue target:me action:selector
	return theSlider
end createSlider

on createView(x, y, width, height, subviews)
	set viewRectSize to current application's NSMakeRect(x, y, width, height)
	set theView to current application's NSView's alloc()'s initWithFrame:viewRectSize
	theView's setSubviews:subviews -- list
	return theView
end createView

on createWindowWithRectAndSubview(subviewItems, x, y, width, height)
	set windowSize to current application's NSMakeRect(x, y, width, height)
	set winStyle to (current application's NSWindowStyleMaskTitled as integer) + (current application's NSWindowStyleMaskClosable as integer) + (current application's NSWindowStyleMaskMiniaturizable as integer) + (current application's NSWindowStyleMaskResizable as integer)
	set theWindow to current application's NSWindow's alloc()'s initWithContentRect:windowSize styleMask:winStyle backing:2 defer:true
	
	repeat with anSubview in subviewItems
		(theWindow's contentView()'s addSubview:anSubview)
	end repeat
	return theWindow
end createWindowWithRectAndSubview

Crashes Script Debugger too