Apple Event: May 7th at 7 am PT

The elusive date picker! Anyone knows how to format a a column to enable it?

I'm looking to format a column that would invoke the picker when the cell is triple-clicked.


I'm aware of the posts on here saying the way to activate it is to to "Insert Current Date" in a cell, but this does nothing for me, no matter how many times I then click on the text of the date afterwards.


I have some old spreadsheets that have cells where it is somehow activated and when I double click the date's text inside the cell it invokes the picker. I thought that maybe pasting the style elsewhere would work but no. If I copy paste the cell, it works, but as soon as I delete the data in the cell, the date picker gets forever deactivated.



Perhaps relevant sidenote: Insert -> Date & Time is always greyed-out for me in tables. Instead I have to go to Table -> Insert Current Date


iMac 27″

Posted on Apr 18, 2024 2:25 PM

Reply
Question marked as Best reply

Posted on Apr 19, 2024 8:53 AM

It feels like it is an old feature that was never fully implemented and was abandoned but they've kept it there for backward compatibility.


I have a date picker script if you really need a date picker. Using Automator you can save it as a service (Quick Action) for Numbers. It will appear in Numbers->Services. You can assign a keyboard shortcut to it to make it easier to use. I tried turning it into a shortcut in the Shortcuts app but it does not respond correctly to input there for some reason. The script uses what looks like an old leftover feature in Mac OS. It works, other than it will not highlight the date you click on. It will return the correct date but there is no visual feedback of which date you clicked on (you'll see what I mean when you try it). I think this is a problem in the date picker function; I couldn't fix it.


To use it: select a cell or range of cells then run the script. Pick a date. Move the hands around to select a time. Click if you want date& time or date only (time will be midnight). If you format the cells to show the date&time a certain way, they will continue to show it that way.





-- Author: Shane Stanley
-- Edited by Badunit for use within the Numbers app
-- July 9, 2021

use scripting additions
use framework "AppKit"

property thedate : missing value
property returncode : missing value

on run
	its performSelectorOnMainThread:("showDatePicker:") withObject:{} waitUntilDone:true
	
	tell application "Numbers" to tell the front document to tell active sheet to tell (first table whose class of selection range is range)
		repeat with c in (get selection range)'s cells
			set value of c to thedate
		end repeat
	end tell
	
end run

on showDatePicker:params
	local params
	
	set datePicker to current application's NSDatePicker's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 100))
	
	-- set datepicker style: choices are 
	-- NSTextFieldAndStepperDatePickerStyle 
	-- NSClockAndCalendarDatePickerStyle
	-- NSTextFieldDatePickerStyle
	
	datePicker's setDatePickerStyle:(current application's NSClockAndCalendarDatePickerStyle)
	
	-- set datepicker elements: choices include 
	-- NSHourMinuteDatePickerElementFlag
	-- NSHourMinuteSecondDatePickerElementFlag
	-- NSTimeZoneDatePickerElementFlag
	-- NSYearMonthDatePickerElementFlag
	-- NSEraDatePickerElementFlag
	
	datePicker's setDatePickerElements:((current application's NSYearMonthDayDatePickerElementFlag) + (current application's NSHourMinuteSecondDatePickerElementFlag as integer))
	
	-- set datepicker initial date
	
	datePicker's setDateValue:(current application's NSDate's |date|())
	
	-- set datepicker size
	
	set theSize to datePicker's fittingSize()
	datePicker's setFrameSize:theSize
	
	-- set the view
	
	set theView to current application's NSView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 200))
	theView's setFrameSize:theSize
	
	-- add the picker to the view
	
	theView's setSubviews:{datePicker}
	
	-- create an alert
	
	set theAlert to current application's NSAlert's alloc()'s init()
	
	-- set up alert
	
	tell theAlert
		its setMessageText:"Pick a Date"
		its setInformativeText:""
		its addButtonWithTitle:"Date & Time"
		its addButtonWithTitle:"Date Only"
		its addButtonWithTitle:"Cancel"
		its setAccessoryView:theView
	end tell
	
	-- show alert in modal loop
	
	set returncode to theAlert's runModal()
	
	
	-- retrieve date. First button is date & time. Second is date with time set to 12:00AM. Third is cancel
	
	if returncode = (current application's NSAlertFirstButtonReturn) then
		set thedate to datePicker's dateValue() as date
	else if returncode = (current application's NSAlertSecondButtonReturn) then
		set thedate to datePicker's dateValue() as date
		set time of thedate to 0
	else
		error number -128
	end if
	
end showDatePicker:




There are a few options in the script for how the date picker will look/work. You can try the others if you don't like the calendar and clock style.

Similar questions

3 replies
Question marked as Best reply

Apr 19, 2024 8:53 AM in response to thegoddelusion

It feels like it is an old feature that was never fully implemented and was abandoned but they've kept it there for backward compatibility.


I have a date picker script if you really need a date picker. Using Automator you can save it as a service (Quick Action) for Numbers. It will appear in Numbers->Services. You can assign a keyboard shortcut to it to make it easier to use. I tried turning it into a shortcut in the Shortcuts app but it does not respond correctly to input there for some reason. The script uses what looks like an old leftover feature in Mac OS. It works, other than it will not highlight the date you click on. It will return the correct date but there is no visual feedback of which date you clicked on (you'll see what I mean when you try it). I think this is a problem in the date picker function; I couldn't fix it.


To use it: select a cell or range of cells then run the script. Pick a date. Move the hands around to select a time. Click if you want date& time or date only (time will be midnight). If you format the cells to show the date&time a certain way, they will continue to show it that way.





-- Author: Shane Stanley
-- Edited by Badunit for use within the Numbers app
-- July 9, 2021

use scripting additions
use framework "AppKit"

property thedate : missing value
property returncode : missing value

on run
	its performSelectorOnMainThread:("showDatePicker:") withObject:{} waitUntilDone:true
	
	tell application "Numbers" to tell the front document to tell active sheet to tell (first table whose class of selection range is range)
		repeat with c in (get selection range)'s cells
			set value of c to thedate
		end repeat
	end tell
	
end run

on showDatePicker:params
	local params
	
	set datePicker to current application's NSDatePicker's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 100))
	
	-- set datepicker style: choices are 
	-- NSTextFieldAndStepperDatePickerStyle 
	-- NSClockAndCalendarDatePickerStyle
	-- NSTextFieldDatePickerStyle
	
	datePicker's setDatePickerStyle:(current application's NSClockAndCalendarDatePickerStyle)
	
	-- set datepicker elements: choices include 
	-- NSHourMinuteDatePickerElementFlag
	-- NSHourMinuteSecondDatePickerElementFlag
	-- NSTimeZoneDatePickerElementFlag
	-- NSYearMonthDatePickerElementFlag
	-- NSEraDatePickerElementFlag
	
	datePicker's setDatePickerElements:((current application's NSYearMonthDayDatePickerElementFlag) + (current application's NSHourMinuteSecondDatePickerElementFlag as integer))
	
	-- set datepicker initial date
	
	datePicker's setDateValue:(current application's NSDate's |date|())
	
	-- set datepicker size
	
	set theSize to datePicker's fittingSize()
	datePicker's setFrameSize:theSize
	
	-- set the view
	
	set theView to current application's NSView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 200))
	theView's setFrameSize:theSize
	
	-- add the picker to the view
	
	theView's setSubviews:{datePicker}
	
	-- create an alert
	
	set theAlert to current application's NSAlert's alloc()'s init()
	
	-- set up alert
	
	tell theAlert
		its setMessageText:"Pick a Date"
		its setInformativeText:""
		its addButtonWithTitle:"Date & Time"
		its addButtonWithTitle:"Date Only"
		its addButtonWithTitle:"Cancel"
		its setAccessoryView:theView
	end tell
	
	-- show alert in modal loop
	
	set returncode to theAlert's runModal()
	
	
	-- retrieve date. First button is date & time. Second is date with time set to 12:00AM. Third is cancel
	
	if returncode = (current application's NSAlertFirstButtonReturn) then
		set thedate to datePicker's dateValue() as date
	else if returncode = (current application's NSAlertSecondButtonReturn) then
		set thedate to datePicker's dateValue() as date
		set time of thedate to 0
	else
		error number -128
	end if
	
end showDatePicker:




There are a few options in the script for how the date picker will look/work. You can try the others if you don't like the calendar and clock style.

The elusive date picker! Anyone knows how to format a a column to enable it?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.