Bingo!
Ahhh....
^.*\R?
(That's not a question. )
Or is it "0 or 1" questions?
I'm happy to say I'm not nerdy enough to know what that means!
Or is it “0 or more than 1” questions?
FWIW, here's a Haskell solution. It's particularly easy to read. The main bits are:
drop 2 . lines
which says exactly that:
drop the first 2 lines
Full Haskell script:
module Main where
main :: IO ()
main =
interact $ unlines . drop 2 . lines
Download Macro(s): Drop 2 lines.kmmacros (8.6 KB)
Macro-Notes
- Macros are always disabled when imported into the Keyboard Maestro Editor.
- The user must ensure the macro is enabled.
- The user must also ensure the macro's parent macro-group is enabled.
System Information
- macOS 13.1
- Keyboard Maestro v10.2
If we're having fun -- shell version of "remove top lines":
REMOVE Top Line(s) -- shell.kmmacros (16.0 KB)
Does require Unix linefeeds, unless you add a conversion step.
Whereas the AppleScript version is line-ending agnostic (like @noisneil's regex) but forces linefeeds (in this version) in the output:
REMOVE Top Line(s) -- AS.kmmacros (16.2 KB)
Since everyone's having fun, this version replaces your whole subroutine Neil with 2 actions and a single explanatory comment. There's no looping and only a single search/replace action using a nifty regex. Hope you enjoy!
Download Macro(s): [SUB] REMOVE Top Line(s).kmmacros (8.6 KB)
Macro-Image
Macro-Notes
- Macros are always disabled when imported into the Keyboard Maestro Editor.
- The user must ensure the macro is enabled.
- The user must also ensure the macro's parent macro-group is enabled.
System Information
- macOS 10.14.6
- Keyboard Maestro v10.2
It's based on another subroutine of mine that you can find in the Macro Library category...
Aside from the niftiness of that regex, I'm also taken by the table formatting in the comment action. Howjadudat?
I created the whole content of the comment in TextEdit and then just copy/pasted into the comment action. There must be a macro for that!
Ah ok, I was thinking it might be nice to use in a variable checker rather than this kind of thing:
Display Text
action accepts the same RTF formatting too…
Yeah but how can you do it within KM? I copied from TextEdit and had a look at the XML but of course it's unreadable Data
. Is there some special magic formatting code?
Instead of taking my guess - try searching the km forum for “rtf format” and be prepared for some research time!
You beat me to it! While digesting rice pudding I realised you could avoid the loop similarly, so here's the "Regex Replace" version of the same, skipping the need for capture groups:
REMOVE Top Line(s) w Variable.kmmacros (16.0 KB)
@noisneil -- you can probably do similar in the other subs that take a variable line number.
Maybe pop a "Custom HTML Prompt" instead?
I don't like to have favourites, but that's my favourite!
I'm having a go with it now, but a few things are giving me a headache; namely: no text wrapping, no dragging/resizing, it slows the macro down by a good 3 seconds and columnised text alignment goes out the window. I'm sure a lot of this is possible, but I don't think it's worth the faff. I think I'm good without the table formatting.
Quick tweak needed. If I leave the Replace With field empty, the replaced lines will be blank, as opposed to gone. What am I missing?
REPLACE LINES Containing String.kmmacros (19 KB)
TEST Caller.kmmacros (20 KB)
The subroutine has a hardcoded \n
in the replacement field…
as in encyclopaedia? (If you remember them )