-
Notifications
You must be signed in to change notification settings - Fork 3
/
Strip Non-Breaking Spaces.applescript
36 lines (29 loc) · 1.15 KB
/
Strip Non-Breaking Spaces.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
// Strip Non-Breaking Spaces.
//
// Strip non-breaking spaces from shell script snippets in user-selected group(s)
//
// 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 search.', multipleSelectionsAllowed:true, emptySelectionAllowed:false});
var count = 0;
listResult.forEach(function(groupName) {
const aGroup = TextExpander.groups.whose({name:{_equals:groupName}})[0];
aGroup.snippets().forEach(function(aSnippet) {
if (aSnippet.contentType() === 'shell_script') {
originalText = aSnippet.plainTextExpansion();
aSnippet.plainTextExpansion = aSnippet.plainTextExpansion().replace(/\u00A0/g,' ');
if (originalText !== aSnippet.plainTextExpansion()) {
count++;
}
}
});
});
// Result is count of updated snippets
count;