Skip to content

Commit 612caff

Browse files
initial commit
0 parents  commit 612caff

8 files changed

+378
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#############
2+
# Mac Files #
3+
#############
4+
.DS_Store
5+
.Trashes
6+
.Spotlight-V100

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Extra Editor Actions for Script Debugger
2+
3+
- This library provides several useful editor functions for ScriptDebugger
4+
5+
- Line Actions:
6+
1. Select Line
7+
2. Copy Line
8+
3. Cut Line
9+
4. Delete Line
10+
![](imgs/selectCutCopyLine.gif)
11+
5. Move Line Up
12+
6. Move Line Down
13+
![](imgs/moveLineUpDown.gif)
14+
15+
- Word Actions:
16+
1. Select Word Under Cursor
17+
2. Copy Word Under Cursor
18+
3. Cut Word Under Cursor
19+
4. Delete Word Under Cursor
20+
![](imgs/selectCutCopyWord.gif)
21+
22+
- camelHumps Word Actions
23+
1. Move Cursor Through camelHumps words
24+
2. Select Words in camelHumps words
25+
3. Delete Words in camelHumps words
26+
![](imgs/selectCopyDeleteCamelHumps.gif)
27+
28+
I use Keyboard Maestro to execute these scripts (example below).
29+
![Alt text](imgs/macro.png?raw=true "Title")

ScriptDebugger Library.applescript

Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
(*
2+
--===============================================================================
3+
4+
Name: ScriptDebugger Library
5+
Description: This library provides several useful editor functions for ScriptDebugger
6+
Author: Kevin Funderburg
7+
Revised: 10/19/18
8+
Version: 1.0
9+
--===============================================================================
10+
*)
11+
use AppleScript version "2.4" -- Yosemite (10.10) or later
12+
use scripting additions
13+
14+
property name : "ScriptDebugger Library"
15+
property id : "com.kfunderburg.library.scriptDebuggerLibrary"
16+
property version : "1.0.0"
17+
18+
property sourceText : missing value
19+
property theSelection : missing value
20+
property theLocation : missing value
21+
property theRange : missing value
22+
property endOfSelection : missing value
23+
property n : missing value
24+
property post : missing value
25+
property pre : missing value
26+
27+
on run
28+
tell application "Script Debugger"
29+
tell front document
30+
set {theLocation, theRange} to (get character range of selection)
31+
set sourceText to source text
32+
set endOfSelection to theLocation + theRange
33+
34+
set n to 0
35+
set post to ""
36+
set pre to ""
37+
end tell
38+
end tell
39+
end run
40+
41+
-- @description
42+
-- Selects, copies, cuts, deletes current line
43+
-- @params: "select", "copy", "cut", "delete"
44+
--
45+
on lineAction(action)
46+
set delims to return & linefeed
47+
tell me to run
48+
tell application "Script Debugger"
49+
tell front document
50+
repeat
51+
considering case
52+
if post = "" then
53+
set forward to character (endOfSelection + n) of sourceText
54+
if forward is in delims then
55+
set post to n
56+
if n = 0 then set n to n + 1
57+
end if
58+
end if
59+
if pre = "" then
60+
set backward to character (endOfSelection - n) of sourceText
61+
if backward is in delims then set pre to n - 1
62+
end if
63+
if post "" and pre "" then exit repeat
64+
set n to n + 1
65+
end considering
66+
end repeat
67+
68+
set theLocation to endOfSelection - (pre)
69+
set theRange to pre + post
70+
set theSelection to {theLocation, theRange}
71+
72+
if action = "select" then
73+
set selection to theSelection
74+
75+
else if action contains "copy" or action contains "cut" then
76+
set the clipboard to characters theLocation thru (theLocation + theRange - 1) of sourceText as string
77+
if action contains "copy" then
78+
display notification (the clipboard) with title "Copied"
79+
else
80+
set action to "delete"
81+
end if
82+
end if
83+
84+
if action contains "delete" then
85+
set selection to {theLocation, theRange + 1}
86+
set selection to ""
87+
end if
88+
89+
end tell
90+
end tell
91+
92+
end lineAction
93+
94+
-- @description
95+
-- Moves a line up or down
96+
-- @params: "up", "down"
97+
--
98+
on moveLine(direction)
99+
set delims to return & linefeed
100+
tell me to run
101+
tell application "Script Debugger"
102+
tell front document
103+
set firstPara to ""
104+
repeat
105+
considering case
106+
107+
if post = "" then
108+
set forward to character (endOfSelection + n) of sourceText
109+
if forward is in delims then
110+
if direction is "down" then
111+
if firstPara is "" then
112+
set firstPara to n
113+
else
114+
set post to n
115+
if n = 0 then set n to n + 1
116+
end if
117+
else
118+
set post to n
119+
if n = 0 then set n to n + 1
120+
end if
121+
end if
122+
end if
123+
124+
if pre = "" then
125+
set backward to character (endOfSelection - n) of sourceText
126+
if backward is in delims then
127+
if direction is "down" then
128+
if n 0 then set pre to n - 1
129+
else
130+
if firstPara is "" then
131+
set firstPara to n
132+
else
133+
set pre to n - 1
134+
end if
135+
end if
136+
end if
137+
end if
138+
139+
if post "" and pre "" then exit repeat
140+
set n to n + 1
141+
end considering
142+
end repeat
143+
144+
set theLocation to endOfSelection - (pre)
145+
set theRange to pre + post
146+
set selection to {theLocation, theRange}
147+
148+
set sel to selection
149+
set p1 to paragraph 1 of sel
150+
set p2 to paragraph 2 of sel
151+
set selection to p2 & return & p1
152+
153+
if direction is "up" then
154+
set {theLocation, theRange} to (get character range of selection)
155+
set selection to {theLocation - ((length of p1) + 1), 0}
156+
end if
157+
158+
end tell
159+
end tell
160+
end moveLine
161+
162+
-- @description
163+
-- Selects, copies, cuts, deletes word under cursor
164+
-- @params: "select", "copy", "cut", "delete"
165+
--
166+
on wordAction(action)
167+
set delims to " :{},()\"" & return & tab & linefeed
168+
tell me to run
169+
tell application "Script Debugger"
170+
tell front document
171+
repeat
172+
considering case
173+
if post = "" then
174+
set forward to character (endOfSelection + n) of sourceText
175+
if forward is in delims then set post to n
176+
end if
177+
if pre = "" then
178+
set backward to character (endOfSelection - n) of sourceText
179+
if backward is in delims then
180+
if n > 0 then set pre to n - 1
181+
end if
182+
end if
183+
if post "" and pre "" then exit repeat
184+
set n to n + 1
185+
end considering
186+
end repeat
187+
188+
set theLocation to endOfSelection - pre
189+
set theRange to pre + post
190+
set theSelection to {theLocation, theRange}
191+
192+
if action = "select" then
193+
set selection to theSelection
194+
195+
else if action contains "copy" or action contains "cut" then
196+
set the clipboard to characters theLocation thru (theLocation + theRange - 1) of sourceText as string
197+
if action contains "copy" then
198+
display notification (the clipboard) with title "Copied"
199+
else
200+
set action to "delete"
201+
end if
202+
end if
203+
204+
if action contains "delete" then
205+
set selection to {theLocation, theRange}
206+
set selection to ""
207+
end if
208+
209+
end tell
210+
end tell
211+
end wordAction
212+
213+
-- @description
214+
-- Selects, copies, cuts, deletes words in camelHumps mode
215+
-- @params: "delete to word end", "delete to word start", "move cursor to next word",
216+
-- "move cursor to next word with selection", "move cursor to previous word",
217+
-- "move cursor to previous word with selection"
218+
--
219+
on camelCaseMode(action)
220+
set delims to " :{},()." & tab & return & linefeed
221+
set caps to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
222+
set invisibles to space & tab & return & linefeed
223+
224+
tell me to run
225+
tell application "Script Debugger"
226+
tell front document
227+
228+
if action contains "delete to word end" then
229+
repeat
230+
set char to character (endOfSelection + n) of sourceText
231+
if n 0 then
232+
considering case
233+
if char is in caps or char is in delims then exit repeat
234+
end considering
235+
end if
236+
set n to n + 1
237+
end repeat
238+
239+
set selection to {theLocation, theRange + n}
240+
set selection to ""
241+
242+
else if action contains "delete to word start" then
243+
244+
repeat
245+
set char to character (theLocation - n) of sourceText
246+
if n > 1 then
247+
considering case
248+
if char is in caps or char is in delims then
249+
if char is in delims then set n to n - 1
250+
exit repeat
251+
end if
252+
end considering
253+
end if
254+
set n to n + 1
255+
end repeat
256+
257+
set selection to {theLocation - n, theRange + n}
258+
set selection to ""
259+
260+
else if action is "move cursor to next word" then
261+
262+
repeat
263+
set char to character (theLocation + n) of sourceText
264+
if n 0 then
265+
considering case
266+
if char is in caps or char is in delims then exit repeat
267+
end considering
268+
end if
269+
set n to n + 1
270+
end repeat
271+
272+
set selection to {theLocation + n, 0}
273+
274+
else if action is "move cursor to next word with selection" then
275+
276+
repeat
277+
set char to character (endOfSelection + n) of sourceText
278+
if n 0 then
279+
considering case
280+
if char is in caps or char is in delims then exit repeat
281+
end considering
282+
end if
283+
set n to n + 1
284+
end repeat
285+
286+
set selection to {theLocation, theRange + n}
287+
288+
else if action is "move cursor to previous word" then
289+
290+
repeat
291+
set char to character (theLocation - n) of sourceText
292+
if n > 1 then
293+
considering case
294+
if char is in caps then
295+
exit repeat
296+
else if char is in delims then
297+
exit repeat
298+
else if char is in invisibles then
299+
set n to n - 1
300+
if character (theLocation - (n - 1)) of sourceText is not tab then
301+
set n to n - 1
302+
exit repeat
303+
end if
304+
end if
305+
end considering
306+
end if
307+
set n to n + 1
308+
end repeat
309+
310+
set selection to {theLocation - n, 0}
311+
312+
else if action is "move cursor to previous word with selection" then
313+
314+
repeat
315+
set char to character (theLocation - n) of sourceText
316+
if n > 1 then
317+
considering case
318+
if char is in caps then
319+
exit repeat
320+
else if char is in delims then
321+
if character (theLocation - (n - 1)) of sourceText is tab then
322+
-- do nothing
323+
else
324+
set n to n - 1
325+
exit repeat
326+
end if
327+
else if char is in invisibles then
328+
if character (theLocation - (n - 1)) of sourceText is not tab then
329+
set n to n - 1
330+
exit repeat
331+
end if
332+
end if
333+
end considering
334+
end if
335+
set n to n + 1
336+
end repeat
337+
338+
set selection to {theLocation - n, theRange + n}
339+
340+
end if
341+
end tell
342+
end tell
343+
end camelCaseMode

imgs/macro.png

114 KB
Loading

imgs/moveLineUpDown.gif

108 KB
Loading

imgs/selectCopyDeleteCamelHumps.gif

151 KB
Loading

imgs/selectCutCopyLine.gif

104 KB
Loading

imgs/selectCutCopyWord.gif

136 KB
Loading

0 commit comments

Comments
 (0)