zenity/internal/zenutil/osascripts/date.gojs

37 lines
1 KiB
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}})
2022-03-28 15:22:39 -04:00
alert.addButtonWithTitle({{json .OK}})
alert.addButtonWithTitle({{json .Cancel}}).keyEquivalent = '\033'
{{- if .Info}}
alert.setInformativeText({{json .Info}})
{{- end}}
{{- if .Extra}}
alert.addButtonWithTitle({{json .Extra}})
{{- end}}
2022-03-24 12:15:11 -04:00
var res = alert.runModal
switch (res) {
case $.NSAlertThirdButtonReturn:
2022-03-28 15:22:39 -04:00
$.puts({{json .Extra}})
2022-03-24 12:15:11 -04:00
case $.NSAlertSecondButtonReturn:
$.exit(1)
}
var fmt = $.NSDateFormatter.alloc.init
fmt.dateFormat = {{json .Format}}
fmt.stringFromDate(date.dateValue)