zenity/internal/zenutil/osascripts/date.gojs

40 lines
1.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.setFrameSize(date.fittingSize)
2022-03-30 10:36:50 -04:00
{{- if .Date}}
date.setDateValue($.NSDate.dateWithTimeIntervalSince1970({{.Date}}))
{{- end}}
2022-03-24 12:15:11 -04:00
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
2022-04-28 18:45:37 -04:00
fmt.locale = $.NSLocale.localeWithLocaleIdentifier("en_US_POSIX");
2022-03-24 12:15:11 -04:00
fmt.dateFormat = {{json .Format}}
fmt.stringFromDate(date.dateValue)