2020-01-10 20:41:13 -05:00
|
|
|
// Code generated by zenity; DO NOT EDIT.
|
2022-03-24 10:37:37 -04:00
|
|
|
//go:build darwin
|
2020-01-10 20:41:13 -05:00
|
|
|
|
2020-01-19 06:57:05 -05:00
|
|
|
package zenutil
|
2020-01-10 20:41:13 -05:00
|
|
|
|
2021-04-08 12:23:17 -04:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"text/template"
|
|
|
|
)
|
2020-01-10 20:41:13 -05:00
|
|
|
|
2020-01-21 07:03:58 -05:00
|
|
|
var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func(v interface{}) (string, error) {
|
|
|
|
b, err := json.Marshal(v)
|
|
|
|
return string(b), err
|
|
|
|
}}).Parse(`
|
2020-12-11 12:33:30 -05:00
|
|
|
{{define "color" -}}
|
2021-02-19 12:46:47 -05:00
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
2021-02-18 21:20:57 -05:00
|
|
|
app.activate()
|
2021-02-19 12:46:47 -05:00
|
|
|
var res=app.chooseColor({defaultColor:{{json .}}})
|
2022-03-26 20:05:52 -04:00
|
|
|
{'rgb('+res.map(x=>Math.round(x*255))+')'}
|
2020-01-21 07:03:58 -05:00
|
|
|
{{- end}}
|
2022-03-24 12:15:11 -04:00
|
|
|
{{define "date" -}}
|
|
|
|
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
|
2022-03-28 15:22:39 -04:00
|
|
|
switch(res){case $.NSAlertThirdButtonReturn:$.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)
|
|
|
|
{{- end}}
|
2021-03-04 21:01:59 -05:00
|
|
|
{{define "dialog" -}}
|
2021-02-19 12:46:47 -05:00
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
2020-01-10 20:41:13 -05:00
|
|
|
app.activate()
|
2022-03-26 20:05:52 -04:00
|
|
|
ObjC.import('stdio')
|
|
|
|
ObjC.import('stdlib')
|
2021-03-03 11:05:11 -05:00
|
|
|
var res=app.{{.Operation}}({{json .Text}},{{json .Options}})
|
2021-03-03 21:52:05 -05:00
|
|
|
if(res.gaveUp){$.exit(5)}
|
|
|
|
if(res.buttonReturned==={{json .Extra}}){$.puts(res.buttonReturned)
|
|
|
|
$.exit(1)}
|
2021-03-04 21:01:59 -05:00
|
|
|
res.textReturned
|
|
|
|
{{- end}}
|
|
|
|
{{define "file" -}}
|
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
app.activate()
|
|
|
|
var res=app.{{.Operation}}({{json .Options}})
|
|
|
|
if(Array.isArray(res)){res.join({{json .Separator}})}else{res.toString()}
|
2020-01-26 11:04:49 -05:00
|
|
|
{{- end}}
|
2021-04-07 09:16:35 -04:00
|
|
|
{{define "list" -}}
|
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
var res=app.chooseFromList({{json .Items}},{{json .Options}})
|
2021-07-08 13:56:28 -04:00
|
|
|
if(res.length!==0)res.join({{json .Separator}})
|
2021-04-07 09:16:35 -04:00
|
|
|
{{- end}}
|
2020-12-11 12:33:30 -05:00
|
|
|
{{define "notify" -}}
|
2021-02-19 12:46:47 -05:00
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
void app.displayNotification({{json .Text}},{{json .Options}})
|
2021-04-30 14:19:14 -04:00
|
|
|
{{- end}}
|
|
|
|
{{define "progress" -}}
|
2021-04-22 10:03:08 -04:00
|
|
|
var app=Application.currentApplication()
|
|
|
|
app.includeStandardAdditions=true
|
|
|
|
app.activate()
|
|
|
|
ObjC.import('stdlib')
|
|
|
|
ObjC.import('readline')
|
2021-04-30 14:19:14 -04:00
|
|
|
{{- if .Total}}
|
|
|
|
Progress.totalUnitCount={{.Total}}
|
|
|
|
{{- end}}
|
|
|
|
{{- if .Description}}
|
|
|
|
Progress.description={{json .Description}}
|
|
|
|
{{- end}}
|
2021-04-22 10:03:08 -04:00
|
|
|
while(true){var s
|
|
|
|
try{s=$.readline('')}catch(e){if(e.errorNumber===-128)$.exit(1)
|
|
|
|
break}
|
2021-04-25 13:34:56 -04:00
|
|
|
if(s.indexOf('#')===0){Progress.additionalDescription=s.slice(1)
|
2021-04-22 10:03:08 -04:00
|
|
|
continue}
|
|
|
|
var i=parseInt(s)
|
2021-04-25 13:34:56 -04:00
|
|
|
if(i>=0&&Progress.totalUnitCount>0){Progress.completedUnitCount=i
|
2021-04-30 14:19:14 -04:00
|
|
|
continue}}
|
|
|
|
{{- end}}`))
|