GUI scripting: Move the editor caret N positions

I think, following may be useful when GUI scripting. It will act on front editor window. When executing as is from Script Editor (or Script Debugger) it will act on script content:
 

--- script: Move the caret several positions
-- written: by KniazidisR, today

tell application "System Events"
	key down 63 -- holding Fn key
	-- move carette 4 times down
	repeat 4 times
		key code 125
	end repeat
	key up 63 -- release Fn key
end tell

-- NOTE:
-- to move up, use 126
-- to move down, use 125
-- to move right, use 124
-- to move left, use 123

 

1 Like

Here is one nice implementation to SCROLL the current MacScripter webpage down:
 

--- script: scroll Safari current webpage 
-- written: by KniazidisR, today

tell application "Safari" to activate

tell application "System Events"
	key down 63 -- holding Fn key
	-- move carette 40 times down (scroll down)
	repeat 40 times
		key code 125
		delay 0.2
	end repeat
	key up 63 -- release Fn key
end tell

-- NOTE:
-- to scroll up, use 126