Hey Folks,
Having grown up with programming editors like Z, vi, and vim I think it’s crazy when an editor cannot rapidly move the editing location (cursor) around to various places – at least to the top, middle and bottom of the visible editing area. (And It’s a bonus when the current line can be moved to those areas as well.)
I was doing something unrelated with UI Browser, when it occurred to me that I might be able to get the visible text area of Script Debugger editor panel.
Sure enough.
My proof-of-concept script below moves the cursor to the top of the editing panel.
The script MUST be SAVED to function properly due to the mechanism it uses to prevent it from operating on itself. (If it is frontmost, it will operate on window 2.)
It’s set to work with SD6, but the SD5 id-string is in there for anyone who needs it.
I’ve tested the script with both version of SD.
Enjoy.
-Chris
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/02/18 21:30
# dMod: 2017/02/18 21:47
# Appl: System Events, Script Debugger 6
# Task: Move cursor to top of visible text editing area.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Script_Debugger, @Move, @Cursor, @Top, @Visible, @Text, @Editing, @Area
------------------------------------------------------------------------------
set myPath to (path to me as text)
if myPath ends with "Script Debugger.app:" then error "Script is not saved!"
# "com.latenightsw.ScriptDebugger5" -- Script Debugger 5
tell application id "com.latenightsw.ScriptDebugger6" -- Script Debugger 6
if myPath = (get file spec of front document as text) then
set scriptDoc to a reference to document 2
set windowNum to 2
else
set scriptDoc to a reference to document 1
set windowNum to 1
end if
if scriptDoc exists then
tell scriptDoc
set startChar to item 1 of getSdVisibleCharacterRange(windowNum) of me
if startChar > 1 then
set sourceText to text startChar thru -1 of (get source text)
set lineLength to length of (get paragraph 1 of sourceText)
set startChar to startChar + lineLength + 1
end if
set selection to {startChar, 0}
end tell
end if
end tell
------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on getSdVisibleCharacterRange(windowNum)
tell application "System Events"
tell (first application process whose bundle identifier is "com.latenightsw.ScriptDebugger6")
tell (window windowNum whose subrole is "AXStandardWindow")
tell text area 1 of scroll area 1 of splitter group 1 of splitter group 1 of splitter group 1 of group 2
set charRange to value of attribute "AXVisibleCharacterRange"
return charRange
end tell
end tell
end tell
end tell
end getSdVisibleCharacterRange
------------------------------------------------------------------------------