@@ -22,7 +22,8 @@ function make_icns {
2222 /bin/mkdir " ${iconset} "
2323
2424 # Create iconset
25- for size in {16,32,64,128,256,512}; do
25+ for size in {16,32,64,128,256,512}
26+ do
2627 /usr/bin/sips --resampleHeightWidth " ${size} " " ${size} " " ${file} " --out " ${iconset} /icon_${size} x${size} .png" & > /dev/null
2728 /usr/bin/sips --resampleHeightWidth " $(( size * 2 )) " " $(( size * 2 )) " " ${file} " --out " ${iconset} /icon_${size} x${size} @2x.png" & > /dev/null
2829 done
@@ -53,7 +54,8 @@ function usage {
5354
5455# Options
5556args=()
56- while [[ " ${1} " ]]; do
57+ while [[ " ${1} " ]]
58+ do
5759 case " ${1} " in
5860 -h | --help)
5961 usage
9395set -- " ${args[@]} "
9496
9597# Check for required arguments
96- if [[ -z " ${notificator_message} " ]]; then
98+ if [[ -z " ${notificator_message} " ]]
99+ then
97100 echo ' A message is mandatory! Aborting…' >&2
98101 exit 1
99102fi
100103
101- readonly bundle_id=" $( tr -cd ' [:alnum:]._-' <<< " ${alfred_workflow_bundleid}" ) "
102- readonly name=" $( tr -cd ' [:alnum:]._- ' <<< " ${alfred_workflow_name}" ) "
104+ readonly bundle_id=" $( /usr/bin/ tr -cd ' [:alnum:]._-' <<< " ${alfred_workflow_bundleid}" ) "
105+ readonly name=" $( /usr/bin/ tr -cd ' [:alnum:]._- ' <<< " ${alfred_workflow_name}" ) "
103106readonly icon=" ${alfred_preferences} /workflows/${alfred_workflow_uid} /icon.png"
104107readonly app=" ${alfred_workflow_cache} /Notificator for ${name} .app"
105108readonly plist=" ${app} /Contents/Info.plist"
106109
107110# Exit early if Notificator exists and was modified fewer than 30 days ago
108- if [[ -e " ${app} " && -n " $( find " ${app} " -depth 0 -mtime -30) " ]]; then
111+ if [[ -d " ${app} " && " $( /bin/date -r " ${app} " +%s) " -gt " $( /bin/date -v -30d +%s) " ]]
112+ then
109113 show_notification
110114 exit 0
111115fi
112116
113117# Pre-build checks
114- if [[ -z " ${bundle_id} " ]]; then
118+ if [[ -z " ${bundle_id} " ]]
119+ then
115120 echo " Workflow is missing the bundle identifier! Aborting…" >&2
116121 exit 1
117122fi
118123
119- if [[ -z " ${name} " ]]; then
124+ if [[ -z " ${name} " ]]
125+ then
120126 echo " Workflow is missing the name! Aborting…" >&2
121127 exit 1
122128fi
123129
124- if [[ ! -f " ${icon} " ]]; then
130+ if [[ ! -f " ${icon} " ]]
131+ then
125132 echo " Workflow is missing the icon! Aborting…" >&2
126133 exit 1
127134fi
128135
129136# Build Notificator
130137readonly jxa_script='
131- // Build argv/argc in a way that can be used from the applet inside the app bundle
132- ObjC.import("Foundation")
133- const args = $.NSProcessInfo.processInfo.arguments
134- const argv = []
135- const argc = args.count
136- for (let i = 0; i < argc; i++) { argv.push(ObjC.unwrap(args.objectAtIndex(i))) }
137-
138- // Notification script
138+ const argv = $.NSProcessInfo.processInfo.arguments.js.map(arg => arg.js)
139139 const app = Application.currentApplication()
140140 app.includeStandardAdditions = true
141141
@@ -160,17 +160,17 @@ readonly jxa_script='
160160 app.displayNotification(message, options)
161161'
162162
163- [[ -d " ${app} " ]] && rm -r " ${app} "
163+ [[ -d " ${app} " ]] && /bin/ rm -r " ${app} "
164164/bin/mkdir -p " ${alfred_workflow_cache} "
165165/usr/bin/osacompile -l JavaScript -o " ${app} " -e " ${jxa_script} " 2> /dev/null
166166
167167# Modify Notificator
168168/usr/libexec/PlistBuddy -c " add :CFBundleIdentifier string ${bundle_id} .notificator" " ${plist} "
169169/usr/libexec/PlistBuddy -c ' add :LSUIElement string 1' " ${plist} "
170- mv " $( make_icns " ${icon} " ) " " ${app} /Contents/Resources/applet.icns"
170+ /bin/ mv " $( make_icns " ${icon} " ) " " ${app} /Contents/Resources/applet.icns"
171171
172172# Redo signature
173- codesign --remove-signature " ${app} "
174- codesign --sign - " ${app} "
173+ /usr/bin/ codesign --remove-signature " ${app} "
174+ /usr/bin/ codesign --sign - " ${app} "
175175
176176show_notification
0 commit comments