Any tip on how to use the new time-date stepper in Xcode?

Hi,

I just noticed the new time-date stepper in Xcode and would like to have some idea how to use it, in particular the graphical version with an integrated calendar and clock object. It looks really nice and would be great to use.

I am just now beginning to experiment with it (mostly trial and error) and would greatly appreciate if anyone could lead me to some useful tips that would slightly straighten the learning curve.

TIA

archseed

Hi,

Just checked and found out that the class of object is NSDatepicker.

There is a thread in this forum that I found, thanks to jonn8, and will try his codes to see how far I get.

Will let everyone know.

archseed:)

Hi,

I guess this is a “call to jon”(sounds like Terminator 2) or someone else who could offer help.

I tried jon’s code (see the thread “Date Picker” by yarnin in this forum) and it works. I can get the date and time when a date is clicked in the calendar.

However, I can’t find a way to change the time. Nothing in the clock on the right side of the calendar seems to respond.

Would appreciate some lead how to activate the clock so that I could change the time.

TIA

archseed

When you set the date of an NSDatePicker, it also sets the time. So, for instance, try this:

set current_date to current date
set time of current_date to ((13 * hours) + (15 * minutes) + 30) --1:15:30 PM
set content of control "date_picker" of window "main" to (current_date)

A variation of this (just setting the NSDatePicker to the current date which includes the current time) is covered in the sample project I made and posted in the thread you referenced:

http://homepage.mac.com/jonn8/as/dist/DatePicker.zip

Jon

Jon,

Thanks for the quick feedback.

I will try some new codes based on your tip and will get back to you if I still can’t figure out the NSDatePicker to do what I want to do.

Since I downloaded your zip file, I will also check there.

Chow.

archseed:)

Jon,

Hi! I’m back so quickly…which can only mean that I’m greatly interested in using the NSDatePicker.

FYI, I downloaded your DatePicker.zip to learn from your technique. Your codes work…to say the least. Now, I think I can do what I want to do – use it to set up an alarm in my script.

BTW, I opted to use the graphical form of the NSDatePicker. It also works seamlessly with your DatePicker codes. Changing the date is easy but changing the time needs some adeptness at capturing the clock hands with the cursor and then moving them around to the right time.

I wonder if there’s a keyboard workaround? If none, the stepper version would be much easier to use.
Thanks a lot for the help.

archseed :smiley:

If you want to use a time offset from the current time, say three hours from now, use this:

set current_date to current date
set current_date to current_date + (3 * hours)
set content of control "date_picker" of window "main" to (current_date)

To add your own stepper to increment the time of a graphical NSDatePicker, add the stepper in IB, set its maximum value to some arbitrarily large number (say, 1000000), name it “time_stepper” and then use this code:

property last_time : missing value

on awake from nib the_object
	set object_name to name of the_object as Unicode text
	if object_name = "main" then
		tell the_object
			center
			set current_date to (current date)
			set content of control "date_picker" to current_date
			set content of stepper "time_stepper" to current_date
			set last_time to (get content of stepper "time_stepper")
			show
		end tell
		
	end if
end awake from nib

on clicked the_object
	set object_name to name of the_object as Unicode text
	if object_name = "time_stepper" then
		set new_time to (get content of the_object)
		if last_time < new_time then
			set the_increment to 1 --seconds, so to move ahead 1 minute, set this to 60; 1 hour: (1 * hours); 1 day: (1 * days); etc.
		else
			set the_increment to -1
		end if
		set last_time to new_time
		tell control "date_picker" of window "main" to set content to (get content) + the_increment
		
	end if
end clicked

Jon

You can see the above technique in a revised version of my demo project (it adjusts the time in 1 minute increments):

http://homepage.mac.com/jonn8/as/dist/DatePicker_xc21.zip (note, this project requires Xcode 2.1)

Jon

Gee thanks!

I will try your latest suggestions and will let you know the outcome.

Chow.

archseed :slight_smile:

Thanks Jon.

Your stepper to help change the time in the clock worked. I had a fun time varying the increment :lol: and learning from you. I must say I learned a lot!

Muchas gracias; arigato; shieh shieh; salamat po, khap khun khap, terimah kasi…in short, thank you very much!

BTW, I could not load your revised DatePicker project directly. I am using Xcode (2.0). I had to paste your script into a new project and then rebuild the interface and objects in IB before I could do the test. Good learning exercise anyway.

Chow.

archseed :slight_smile: