-
Notifications
You must be signed in to change notification settings - Fork 0
/
Choose and paste from 500+ generic AppleScript functions.kmmacros
360 lines (339 loc) · 10.5 KB
/
Choose and paste from 500+ generic AppleScript functions.kmmacros
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Activate</key>
<string>Normal</string>
<key>CreationDate</key>
<real>551631812.997293</real>
<key>Macros</key>
<array>
<dict>
<key>Actions</key>
<array>
<dict>
<key>ActionU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TAwIEFwcGxlU2NyaXB0
IFByZWx1ZGUgRnVuY3Rpb25zIG1l
bnUuKyBnZW5lcmljIGFuZCBmaWxl
LXN5c3RlbSBmdW5jdGlvbnMgZm9y
IEFwcGxlU2NyaXB0ICl9AQAAACMA
AAABAAAABwAAAFRYVC5ydGYQAAAA
Nm8XYrYBAAAAAAAAAAAAAA==
</data>
<key>Title</key>
<string>Adjust the value of preludeApplescript below to a local path on your system</string>
</dict>
<dict>
<key>ActionUID</key>
<integer>1903</integer>
<key>DisplayKind</key>
<string>Clipboard</string>
<key>HonourFailureSettings</key>
<true/>
<key>IncludeStdErr</key>
<false/>
<key>MacroActionType</key>
<string>ExecuteJavaScriptForAutomation</string>
<key>Path</key>
<string></string>
<key>Text</key>
<string>(() => {
"use strict";
// ---------------------- MAIN ----------------------
const main = () => {
const inner = () => {
const
fpFolder = "~/prelude-applescript",
menuJSONFile = "asPreludeMenu.json";
return either(
alert("AppleScript functions")
)(
// Returned to Keyboard Maestro
// for pasting.
x => x
)(
bindLR(
doesDirectoryExist(fpFolder) ? (
Right(fpFolder)
) : Left(`Directory not found: ${fpFolder}`)
)(
fpDir => bindLR(
readFileLR(
combine(fpDir)(menuJSONFile)
)
)(
json => bindLR(
jsonParseLR(json)
)(
dict => bindLR(
showMenuLR(true)(
"AppleScript Prelude Functions"
)(Object.keys(dict))
)(
ks => Right(
ks.map(k => dict[k])
.join("\n\n\n")
)
)
)
)
)
);
};
return inner();
};
// ---------------- JS PRELUDE - JXA ----------------
// alert :: String => String -> IO String
const alert = title =>
s => {
const sa = Object.assign(
Application("System Events"), {
includeStandardAdditions: true
});
return (
sa.activate(),
sa.displayDialog(s, {
withTitle: title,
buttons: ["OK"],
defaultButton: "OK"
}),
s
);
};
// doesDirectoryExist :: FilePath -> IO Bool
const doesDirectoryExist = fp => {
const ref = Ref();
return $.NSFileManager.defaultManager
.fileExistsAtPathIsDirectory(
$(fp)
.stringByStandardizingPath, ref
) && ref[0];
};
// readFileLR :: FilePath -> Either String IO String
const readFileLR = fp => {
const
e = $(),
ns = $.NSString
.stringWithContentsOfFileEncodingError(
$(fp).stringByStandardizingPath,
$.NSUTF8StringEncoding,
e
);
return ns.isNil() ? (
Left(ObjC.unwrap(e.localizedDescription))
) : Right(ObjC.unwrap(ns));
};
// ------------------- JS PRELUDE -------------------
// Left :: a -> Either a b
const Left = x => ({
type: "Either",
Left: x
});
// Right :: b -> Either a b
const Right = x => ({
type: "Either",
Right: x
});
// bindLR (>>=) :: Either a ->
// (a -> Either b) -> Either b
const bindLR = m =>
mf => undefined !== m.Left ? (
m
) : mf(m.Right);
// combine (</>) :: FilePath -> FilePath -> FilePath
const combine = fp =>
// Two paths combined with a path separator.
// Just the second path if that starts
// with a path separator.
fp1 => Boolean(fp) && Boolean(fp1) ? (
"/" === fp1.slice(0, 1) ? (
fp1
) : "/" === fp.slice(-1) ? (
fp + fp1
) : `${fp}/${fp1}`
) : fp + fp1;
// either :: (a -> c) -> (b -> c) -> Either a b -> c
const either = fl =>
// Application of the function fl to the
// contents of any Left value in e, or
// the application of fr to its Right value.
fr => e => "Either" === e.type ? (
undefined !== e.Left ? (
fl(e.Left)
) : fr(e.Right)
) : undefined;
// jsonParseLR :: String -> Either String a
const jsonParseLR = s => {
try {
return Right(JSON.parse(s));
} catch (e) {
return Left(
`${e.message} (line:${e.line} col:${e.column})`
);
}
};
// showMenuLR :: Bool -> String -> [String] ->
// Either String [String]
const showMenuLR = blnMult =>
title => xs => 0 < xs.length ? (() => {
const sa = Object.assign(
Application("System Events"), {
includeStandardAdditions: true
});
sa.activate();
const v = sa.chooseFromList(xs, {
withTitle: title,
withPrompt: `Select${
blnMult ? (
` one or more of ${
xs.length.toString()}`
) : ":"}`,
defaultItems: xs[0],
okButtonName: "OK",
cancelButtonName: "Cancel",
multipleSelectionsAllowed: blnMult,
emptySelectionAllowed: false
});
return Array.isArray(v) ? (
Right(v)
) : Left(`User cancelled ${title} menu.`);
})() : Left(`${title}: No items to choose from.`);
return main();
})();</string>
<key>TimeOutAbortsMacro</key>
<true/>
<key>TrimResults</key>
<true/>
<key>TrimResultsNew</key>
<true/>
<key>UseText</key>
<true/>
</dict>
<dict>
<key>ActionUID</key>
<integer>1904</integer>
<key>IsDisclosed</key>
<false/>
<key>MacroActionType</key>
<string>BringWindowsForward</string>
</dict>
<dict>
<key>Action</key>
<string>Paste</string>
<key>ActionUID</key>
<integer>1905</integer>
<key>IsDisclosed</key>
<false/>
<key>MacroActionType</key>
<string>CutCopyPaste</string>
<key>TimeOutAbortsMacro</key>
<true/>
</dict>
</array>
<key>CreationDate</key>
<real>551631369.62312603</real>
<key>CustomIconData</key>
<string>KMEC=Rounded=KMCOLOR:239,239,239,255=↓=86=6=0=0=KMCOLOR:255,0,0,255</string>
<key>ModificationDate</key>
<real>667396002.36522102</real>
<key>Name</key>
<string>Choose and paste from 500+ generic AppleScript functions</string>
<key>Triggers</key>
<array>
<dict>
<key>FireType</key>
<string>Pressed</string>
<key>KeyCode</key>
<integer>0</integer>
<key>MacroTriggerType</key>
<string>HotKey</string>
<key>Modifiers</key>
<integer>2304</integer>
</dict>
</array>
<key>UID</key>
<string>2BFE9CF8-E619-4EC3-A071-D88F6EC5B19C</string>
</dict>
</array>
<key>Name</key>
<string>Prelude</string>
<key>Targeting</key>
<dict>
<key>Targeting</key>
<string>Excluded</string>
<key>TargetingApps</key>
<array>
<dict>
<key>BundleIdentifier</key>
<string>com.hogbaysoftware.TaskPaper3.direct</string>
<key>Name</key>
<string>TaskPaper</string>
<key>NewFile</key>
<string>/Applications/TaskPaper.app</string>
</dict>
<dict>
<key>BundleIdentifier</key>
<string>com.omnigroup.OmniGraffle7</string>
<key>Name</key>
<string>OmniGraffle</string>
<key>NewFile</key>
<string>/Applications/OmniGraffle.app</string>
</dict>
<dict>
<key>BundleIdentifier</key>
<string>com.apple.finder</string>
<key>Name</key>
<string>Finder</string>
<key>NewFile</key>
<string>/System/Library/CoreServices/Finder.app</string>
</dict>
</array>
</dict>
<key>ToggleMacroUID</key>
<string>89CF234D-1ABC-4CDE-9BAF-87F943C2FE30</string>
<key>UID</key>
<string>7B9EF0DB-38C6-46C7-8B06-29AA6AC43D1A</string>
</dict>
</array>
</plist>