Shortcuts for delete / copy / move line?

Hello!

I would like to delete / copy / move lines in AppleScripts edited with ScriptDebugger.
I couldn’t find any shortcuts for this.

I’ve just begun with Script Debugger, so I supposed that I’m the only one that didn’t find this yet, but then I discovered this somehow similar thread, so I thought I better ask here about it.

I would appreciate any help.

Regards,
Vlad

I presume you mean delete/copy without having to select, in which case the answer is no.

Hey, ShaneStanley!

Yes, I was searching for delete / copy / move without selecting the line.

Ok, I’ll try to do it otherwise then.

Thanks1

Regards,
Vlad

Hey @Vlad,

Unfortunately Script Debugger lacks quite a number of editing niceties…

The most glaring is select-current-line, which every programming editor on the planet has these days.

Unfortunately Apple’s Cocoa Text Suite has very poor scripting capability – you should have seen Script Debugger back when it used the WASTE text engine in pre-OSX days gone by.

Nevertheless the delete-current-line issue is easily solved if you have the Satimage.osax installed.

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/06/30 19:01
# dMod: 2018/06/30 19:35 
# Appl: Script Debugger 7
# Task: Delete Current line
# Libs: None
# Osax: Satimage.osax -- http://tinyurl.com/satimage-osaxen
# Tags: @Applescript, @Script, @Satimage.osax, @Delete, @Current, @Line
----------------------------------------------------------------

tell application id "com.latenightsw.ScriptDebugger7"
   tell document 1
      set scriptText to source text
      set charOffset to item 1 of (get character range of selection)
   end tell
end tell

set charOffset to charOffset - 1
set regexPattern to "(?m)\\A(.{" & charOffset & "})"
set scriptText to change regexPattern into "\\1ˆ" in scriptText with regexp
set {match_Pos, match_Len} to {matchPos, matchLen} of (find text "^.*ˆ.*$\\R?" in scriptText with regexp)
set match_Pos to match_Pos + 1
set match_Len to match_Len - 1

tell application id "com.latenightsw.ScriptDebugger7"
   tell document 1
      set selection to {match_Pos, match_Len}
      set selection to ""
   end tell
end tell

----------------------------------------------------------------

I need to tweak this, so it completely deletes empty lines when working from the bottom upward.

Currently the only place it fails is when the cursor is in the last line, AND that line is empty.

-Chris

We do, however, have a Feature Requests section here. It’s interesting to note that the above-mentioned thread was the first time that particular command had been requested in SD’s entire history.

I’ll take your word for it, but I have to say that the Mac standard command-shift-left followed by command-shift-right doesn’t strike me as too onerous.

In cases like this it’s easier and safer to use ASObjC:

use AppleScript version "2.5" 
use framework "Foundation"
use scripting additions

tell application id "com.latenightsw.ScriptDebugger7"
	tell document 1
		set scriptText to source text
		set selRange to (get character range of selection)
	end tell
end tell

set scriptText to current application's NSString's stringWithString:scriptText
set selRange to scriptText's paragraphRangeForRange:{(item 1 of selRange) - 1, item 2 of selRange}

tell application id "com.latenightsw.ScriptDebugger7"
	tell document 1
		set selection to {(location of selRange) + 1, |length| of selRange}
		set selection to ""
	end tell
end tell
1 Like

Hello again, ShaneStanley!

I’d make a feature request for select / copy / duplicate / move line, but there’s no link for the Feature Requests in your reply. Could you please tell me where exactly I could make this?

And thanks @ccstone and @ShaneStanley for the scripts! I’ve just begun with the AppleScript so it will take a while until I’ll be able to understand everything is going on here… :slight_smile:
In the meantime I was lazy :wink: and made me the missed shortcuts with Keyboard Maestro.

It would really be nice if Script Debugger would offer them directly… even Eclipse has something like this! :smiley:

Thanks again!

Regards,
Vlad

When you create a new topic and type in a title, there’s a popup underneath (Uncategorized). Choose Feature Request there.

Thanks, ShaneStanley, I’ve just wrote a Feature Request.

I have a solution using Keyboard Maestro that seems to work.
This is just the selection step – which is the hardest.
Operating on the selection is easy enough.

image

These two simple Actions can easily be done in AppleScript as well.

But the problem that all of these have is that they don’t select the entire block where OPT-RETURN has been used to continue the statement on the next line.

Any ideas on how to handle that?

OK, this works IF the cursor is anywhere on the first line of the block:

I’m sure all that can be done in AppleScript – it was just quickest for me to do in Keyboard Maestro.

And that’s also a problem should this and similar commands be implemented internally: should they really be based on a paragraph/line, or on statements, or on statements only if in the first (or last) line? I can see arguments all ways, and I don’t see an precedent in other editors, though I haven’t scoured the planet.

Maybe people can offer there thoughts over here:

Shortcuts for basic line manipulation

Anyway, here’s a script that handles the full statement case:

use AppleScript version "2.5"
use framework "Foundation"
use scripting additions

tell application id "com.latenightsw.ScriptDebugger7"
	tell document 1
		set scriptText to source text
		set {theLocation, theLength} to (get character range of selection)
	end tell
end tell
set theLocation to theLocation - 1 -- for zero-based counting
set scriptText to current application's NSString's stringWithString:scriptText
repeat
	set {theLocation, theLength} to (scriptText's paragraphRangeForRange:{theLocation, theLength}) as list -- easier to work with list than record
	if ((scriptText's substringToIndex:(theLocation + theLength - 1))'s hasSuffix:"¬") then
		set theLength to theLength + 1
	else if theLocation > 2 and ((scriptText's substringToIndex:(theLocation - 1))'s hasSuffix:"¬") then
		set theLocation to theLocation - 1
	else
		exit repeat
	end if
end repeat
tell application id "com.latenightsw.ScriptDebugger7"
	tell document 1
		set selection to {theLocation + 1, theLength}
		set selection to ""
	end tell
end tell

In my opinion: This commands should handle a line (= between column 0/1 and CR).
This is the way the editors that I used und use (right now, daily: BBEdit on the Mac, Eclipse, Ultra Edit, Visual Studio Code and the editor from the SAP GUI on a PC) work.

Regarding the continuation character in AppleScript: I haven’t wrote enough AppleScript to have a feeling what is right or wrong.
However my first thought would be to ignore it - you could also write everything in one really long line - and go with the line in this case too.

This is a little bit of a late reply, but I wrote a script library that does perform the functions discussed here as well as some other common editor functions, give it a looksie and see if you like :wink: - Script Library: Extra Editor Actions for Script Debugger.

It looks like everything I was asking for!

Thanks, Kevin!