Hey Mitchell,
Considering the Script Editor is over 20 years old now it's astonishing just how brain-dead it is.
A programming editor that doesn't even have a Go-To Line function...
Nevertheless – you're a programmer and scripter aren't you? So have a close look at the app's dictionary, before you get too flummoxed.
-------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/01/28 05:00
# dMod: 2017/01/28 05:16
# Appl: Script Editor
# Task: Go-To the Specifed Line
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Script_Editor, @Go-To, @Specifed, @Line
-------------------------------------------------------------------------
tell application "Script Editor"
set goToLine to text returned of (display dialog "Insert a Line Number:" default answer "" with title "Go-To Line" giving up after 30)
tell front document
set docSrc to contents
set theLines to paragraphs of docSrc
if length of theLines ≥ goToLine then
set theLines to items 1 thru goToLine of theLines
set theoffset to count of characters of item goToLine of theLines
set AppleScript's text item delimiters to linefeed
set theLines to theLines as text
set charCount to count of characters of theLines
set selection to characters (charCount - theoffset + 1) thru charCount
else
error "The specified line is outside the scope of the text!"
end if
end tell
end tell
-------------------------------------------------------------------------
** I'm not doing error-checking for empty lines and other pitfalls – I leave that as an exercise for the reader.
Now then – the above is not how I would tackle this problem on my system – I'd use the Satimage.osax.
-------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/01/28 05:00
# dMod: 2017/01/28 07:12
# Appl: Script Editor
# Task: Go-To the Specifed Line Using the Satimage.osax
# Libs: None
# Osax: Satimage.osax { http://tinyurl.com/dc3soh }
# Tags: @Applescript, @Script, @Script_Editor, @Go-To, @Specifed, @Line, @Satimage.osax
-------------------------------------------------------------------------
tell application "Script Editor"
set goToLine to 10
tell front document
set docSrc to contents
set matchRecList to fnd("^.+", docSrc, true, false) of me
if length of matchRecList ≥ goToLine then
set {match_Pos, match_Len, match_Result} to {matchPos, matchLen, matchResult} of (item goToLine of matchRecList)
set selection to characters (match_Pos + 1) thru (match_Pos + 1 + match_Len)
end if
end tell
end tell
-------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------
on fnd(_find, _data, _all, strRslt)
try
find text _find in _data all occurrences _all string result strRslt with regexp without case sensitive
on error
return false
end try
end fnd
-------------------------------------------------------------------------
** Again – I'm not doing the error-checking I'd do for a production script – this is left to the reader.
I use techniques similar to this to work with text in Script Debugger as well. I do such things as Select Current Line and Duplicate Selection – which oddly enough are features SD does NOT have.
NOTE: Setting the selection in the Script Editor does NOT move the view of the editing pane to the location of the selection. If you want to do that then you need to add the keystroke for “Jump to Selection” (⌘J) to your macro.
** Script Editor comes with quite a few scripts you can use as examples.
So. This stuff is not exactly fun – but it's fairly easily done.
-Chris