I keep a markdown-style task list in a plain text file. I use a macro to quick-enter new tasks without having to open up the document, basically prompting me for task name and then appending to the end of the task list file while I get on with other things.
If the last character of the file is at the end of the (previously last) task, the new task gets appended on to that existing line (which I don't want). But if the last character is at the beginning of a new line, after that last task, then the new task is inserted on that new line (which I DO want).
But if I force a new line using Append Text, then sometimes I'll end up with blank lines between tasks, which I don't want.
I want to force my new task to the beginning of a new line, while not having any blank (empty) lines between my new task and my previous task. I don't know how to test for whether I'm at the beginning of a new line, so that I can craft the appropriate Append Text.
The thread at Get Text Cursor Position seems to indicate that I can't go to CMD-DownArrow and then test for position index = 0.
Is there any other good way of figuring out, when I move to the end of a file, if my cursor is at a fresh new empty line or not?
Thank you all, please forgive my clumsy descriptions, it's my first forum post and I'm still learning.
BBEdit is as indispensable to me as KM. While it's hugely useful even in its free from, it's worth every penny. I would almost feel guilty using the free version.
Thank you all. I made it work with a modification of this advice:
but instead of testing CLIPBOARDSEED, I tested whether the copied character was a LineFeed. Then I realized I had to actually have the file open in a text editor, and I fixed that too.
I've never thought of using BBEdit as a utility like this. I currently have VSCode installed because I'm trying to have my text-writing environment identical to my obligate work Windows environment. I think I could do similar scripting there, but I've always had it in my mind to get the more... um... noble BBEdit.
Like @macdevign_mac, I'll like to see how BBEdit can work with KM. I'm starting to find a few examples online.
Again, thank you all. This community is so full of ingenuity, it's a happy discovery for me.
AppleScript can get a great deal of information about the selection (or character position) in BBEdit:
From there you can do all kinds of wondrous things...
A brief example:
tell application "BBEdit"
tell front text window
# return (get selection) --> uncomment to examine properties-of-selection.
set charOffset to characterOffset of (get selection)
set beforeCharOffset to (its characters (charOffset - 1) thru charOffset) as text
set charOffsetContents to character charOffset as text
set charactersAfterSelection to ((characters charOffset thru -1) as text)
set charactersAfterSelectionLength to length of charactersAfterSelection
end tell
end tell
So β rather than having to mimic user actions you can precisely script what you want to do.
Add some text to a document, and move the cursor to the end of it β then run this script:
property LF : linefeed
set itemName to text returned of (display dialog Β¬
"Enter Markdown Item Name" buttons Β¬
{"Cancel", "OK"} default button Β¬
"OK" default answer "")
tell application "BBEdit"
tell front text window
set lastCharacter to its last character
set charOffsetOfSelection to characterOffset of (get selection)
if characterOffset of lastCharacter < charOffsetOfSelection then
set selection to LF & "- [ ] " & itemName
select insertion point after selection
end if
end tell
end tell
I like VSC very much and use it for a fair number of things, but BBEdit will always stay on my system when it can do things like this β and no other app can...