-
Notifications
You must be signed in to change notification settings - Fork 3
/
Change Case Behavior.applescript
49 lines (43 loc) · 1.95 KB
/
Change Case Behavior.applescript
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
// Change Case Behavior.
//
// Allow user to select groups then to select desired case sensitivity behavior for those
// groups, then apply those changes.
//
// Copyright 2018 SmileOnMyMac, LLC. See LICENSE.md for license terms.
// Preliminaries
TextExpander = Application('TextExpander');
Finder = Application('Finder');
currentApp = Application.currentApplication();
currentApp.includeStandardAdditions = true;
// Get sorted list of group names
groupNames = TextExpander.groups.name().sort();
// Let user pick group(s) to process
listResult = currentApp.chooseFromList(groupNames, {withTitle:'Groups', withPrompt:'Please pick group(s) to change.', multipleSelectionsAllowed:true, emptySelectionAllowed:false});
// Let user pick behavior to apply to groups
caseChoice = currentApp.chooseFromList(['Case Sensitive (aB, Ab, ab, differ)', 'Ignore Case (aB, Ab, ab same)', 'Adapt to Case of Abbreviation'], {withTitle: 'Choose New Case Behavior', withPrompt:'Please choose the case behavior to apply to all of the previously selected groups, or click Cancel to exit without making any changes.'});
newAbbreviationMode = undefined;
switch(caseChoice[0]) {
case 'Case Sensitive (aB, Ab, ab, differ)':
newAbbreviationMode = 'case sensitive';
break;
case 'Ignore Case (aB, Ab, ab same)':
newAbbreviationMode = 'ignore case';
break;
case 'Adapt to Case of Abbreviation':
newAbbreviationMode = 'match case';
break;
}
// If user picked, go ahead and apply the changes
if (newAbbreviationMode !== undefined) {
listResult.forEach(function(groupName) {
const aGroup = TextExpander.groups.whose({name:{_equals:groupName}})[0];
aGroup.snippets().forEach(function(aSnippet) {
if (aSnippet.abbreviationMode() != newAbbreviationMode) {
aSnippet.abbreviationMode = newAbbreviationMode;
}
});
});
currentApp.displayDialog('Change completed.', {buttons:['OK'], defaultButton:'OK'});
} else {
currentApp.displayDialog('No changes made.', {buttons:['OK'], defaultButton:'OK'});
}