Skip to content

Instantly share code, notes, and snippets.

@1024jp
Last active December 24, 2024 00:18
Show Gist options
  • Select an option

  • Save 1024jp/6f1a28df9c2caf0f0104 to your computer and use it in GitHub Desktop.

Select an option

Save 1024jp/6f1a28df9c2caf0f0104 to your computer and use it in GitHub Desktop.
Insert new line above current line
(*
Insert new line above current line
[version] 1.0.0
[release] 2014-11-22
[author] 1024jp <http://wolfrosch.com/>
[licence] MIT License
*)
tell application "CotEditor"
if not (exists front document) then return
tell front document
-- get current selection range
set {loc, len} to range of selection
set {lineLoc, lineLen} to line range of selection
-- select whole line
set line range of selection to {lineLoc, lineLen}
-- insert a new line before selection
set contents of selection to ("\n" & contents of selection)
-- reset selection
set range of selection to {loc + 1, len}
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment