zenity/internal/zenutil/osascripts/date.gojs

31 lines
918 B
Text
Raw Normal View History

2022-03-24 12:15:11 -04:00
var app = Application.currentApplication()
app.includeStandardAdditions = true
app.activate()
ObjC.import('Cocoa')
ObjC.import('stdio')
ObjC.import('stdlib')
var date = $.NSDatePicker.alloc.init
date.setDatePickerStyle($.NSDatePickerStyleClockAndCalendar)
date.setDatePickerElements($.NSDatePickerElementFlagYearMonthDay)
date.setDateValue($.NSDate.dateWithTimeIntervalSince1970({{.Date}}))
date.setFrameSize(date.fittingSize)
var alert = $.NSAlert.alloc.init
alert.setAccessoryView(date)
alert.setMessageText({{json .Text}})
{{- if .Info}}alert.setInformativeText({{json .Info}}){{- end}}
{{- range .Buttons}}alert.addButtonWithTitle([{{json .}}]){{end}}
var res = alert.runModal
switch (res) {
case $.NSAlertThirdButtonReturn:
$.puts({{json .Buttons}}[2])
case $.NSAlertSecondButtonReturn:
$.exit(1)
}
var fmt = $.NSDateFormatter.alloc.init
fmt.dateFormat = {{json .Format}}
fmt.stringFromDate(date.dateValue)