-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathRenumber-Macro-Prefix-Numbers.applescript
53 lines (43 loc) · 1.76 KB
/
Renumber-Macro-Prefix-Numbers.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
49
50
51
52
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
try
tell application "Keyboard Maestro"
set dialogResult to display dialog ¬
"Enter the starting number or click clear to remove number prefix." default answer 0 ¬
with title "Renumber Macro Prefix Numbers" buttons {"Cancel", "Clear", "OK"} ¬
default button "OK" with icon ¬
POSIX file "/System/Volumes/Data/Applications/Keyboard Maestro.app/Contents/Resources/kmicon.icns"
set startNum to dialogResult's text returned as number
set sel to selection
if class of item 1 of sel ≠ macro then error "Invalid selection, please select macro(s)"
set n to startNum
repeat with m in sel
set oldname to m's name
if dialogResult's button returned = "Clear" then
if character 3 of oldname = ")" then -- 2 digit number prefix
set newname to characters 4 thru -1 of oldname as text
else if character 2 of oldname = ")" then -- 1 digit number prefix
set newname to characters 3 thru -1 of oldname as text
else -- doesn't have a number prefix
set newname to oldname
end if
else
if n < 10 then set n to "0" & n
if character 3 of oldname is ")" then
set newname to n & (characters 3 thru -1 of oldname) as text
else if character 2 of oldname is ")" then -- 1 digit number prefix
set newname to n & (characters 2 thru -1 of oldname) as text
else -- doesn't have a number prefix
set newname to (n & ")" & oldname) as text
end if
set n to n + 1
end if
set m's name to newname
end repeat
end tell
on error errMsg number errNum
if errNum ≠ -128 then
display dialog errMsg & return & return & errNum buttons {"Cancel", "OK"} ¬
default button "OK" with icon caution
end if
end try