How to modify the contents of a Date Picker

Hello all,

I’m wondering how I can take a full date as a string or date value and write it to a Date Picker user interface Object.

I’ve tried a few methods to no avail, any help would be a godsend!

Thanks!

Try something like this:

-- set content of someDatePicker to someDate
set content of control "date" of super view of theObject to (current date)

This doesn’t exactly work. It may if I knew what super view was, or how to use it, but I’m just lost. I don’t know what the object should be, this isn’t run inside of an event handler, and doesn’t exactly have a value for theObject.

Here is the code as I have it now.

tell box 1 of tab view item "settingsTab" of tab view 1 of window "preferencesSetup"
set content of control "startTime" of super view of control "startTime" to startTime
end tell

Which doesn’t work.

Here is a piece of code from one of my projects that has a lot of date pickers:


on awake from nib theObject

	if object_name = "main" then
		--Now, to fill in all the date windows with starting data
		tell theObject --All this date stuff is taken directly from Jon's DatePicker.zip
			center
			set use_date to (current date)
			set content of control "school_first" to use_date
			set content of control "school_last" to (use_date + (46 * weeks))
			set {use_date's month, use_date's day} to {October, 27}
			set content of control "aut_begin" to use_date

  ---  blah, blah, blah.....
                 end tell
	end if
end awake from nib

See if that helps. All the named content of control objects are date pickers. I start off with the current date, and just add time intervals, or change the month and day, and keep setting all of the date pickers to different dates.

super view is a property of the view class; That’s not something that’s required, but it can sometimes be used to simplify references.

It sounds like your problem is finding the right way to refer to the date picker control.

Okay, two things!

Firstly, the above doesn’t seem to work. The date is set from the picker to a variable, then written to a plist, then read from that plist as a string, then set to the UI. Why would this not be working?

Secondly, I’ve now run into a bigger problem, and my head has exploded!

I need to set a nightly crontab that runs shutdown -h now. I have a file that contains the following code.

PATH="/sbin:/bin:/usr/sbin:/usr/bin"
00	23	*	*	0	shutdown -h now
00	23	*	*	1	shutdown -h now
00	23	*	*	2	shutdown -h now
00	23	*	*	3	shutdown -h now
00	23	*	*	4	shutdown -h now
00	23	*	*	5	shutdown -h now
00	23	*	*	6	shutdown -h now

How could I possibly take this code from the datePicker, and write the hour that is being set into this file? My problem is my lack of knowledge of awk and grep, I’m not sure how to isolate the hour and minute from the date value. Also, I’m not sure how to display a 12-hour clock, but then convert it to 24-hour for this file! Oh my lord!

Aw :frowning:

This is maybe not the best way to do it but if you need to get a time in 24 hour clock from a Applescript date this will return just the time as a string. Get you started anyway and in 24 hour if the time is after 12PM

set thedate to characters 12 through end of ((current date) as «class isot» as string) as string
set now to current date
set theHours to hours of now
set theMinutes to minutes of now
set theSeconds to seconds of now
return {theHours, theMinutes, theSeconds}