How to prevent Script Editor from scrolling (and losing cursor location) on compile?

Solution 1:

I just tried what you explained with script editor in Sierra and did not experience the same problem you are experiencing. This may not be the best solution to your questions but it will definitely save you some time. Why not just throw in a little comment at the place in the script where you want your cursor located after a file save. Just adding something like --cursorand copy that commented --cursor to your clipboard then after you do ⌘ command + S , then go ahead and click ⌘ command + F (which will open the find field right there in your script editor window) then you could click ⌘ command + V (which would automatically paste that short commented line into the find field) this of course will highlight that text in your script and bring you right to its location.


UPDATE - NEW DIFFERENT APPROACH

Just add this handler to the bottom of any one of your script files.(I like to put my handlers at the bottom of the script to keep them from cluttering up the rest of the body of the script)

Calling the handler at any point in your script will ultimately get the coordinates of your scrollbar, then it will automatically save the current script with the keycode command , then will return your scrollbar back to its original coordinates. Just comment or un comment the calling of the handler depending on whether you want to save or not save your document. Leaving the calling of the handler as un commented As I have it set now, Will automatically save your script every time you click the “RUN” button within script editor.

on setScrollPosition()
    tell application (path to frontmost application as text) to (path to me as text)
    set theFile to result
    set theFile2 to alias theFile
    tell application "Finder"
        set theName to name of theFile2
    end tell
    delay 1
    tell application "System Events"
        get value of value indicator 1 of scroll bar 1 of scroll area 1 of splitter group 1 of splitter group 1 of window theName of application process "Script Editor"
        set thePosition to the result
        key code 1 using command down
        delay 10
        set value of value indicator 1 of scroll bar 1 of scroll area 1 of splitter group 1 of splitter group 1 of window theName of application process "Script Editor" to thePosition
    end tell
end setScrollPosition

setScrollPosition()

SIDE NOTE: I have the delay set 5 which gives me time to play around with the scroll position after clicking “Run” to see if it actually works or not (which it does in the latest version of Sierra) you can adjust the delay value or comment it out if you don't need it.