this works well but i want to enhance the macro where if there is no text selected that i will be able to run the macro by cutting the whole line where the cursor is (again only if not text is selected)
is that possible at all? and if so how do i best approach this
The exact method will depend on the application, but have a look in the menu items for something that is only enabled when some text is selected. So in TextEdit you might check the "Cut" item and if it wasn't enabled (nothing selected) you'd select the whole line:
ahh very interesting @Nige_S ! thanks so much for this insight
Sadly, in my main app obsidian the menu seems to be enables with both text selected or cleared (dont know if this is an electron thing...). any other tricks like this
Then it may not matter -- in Obsidian, โX generally cuts the selection or, if there is no selection, cuts the line the insertion point is in. Just what you want!
Is there a situation where that isn't working for you? If so, provide more details and somebody might be able to find a solution.
so if text is selected it will launch the macro commands on the selected text and if nothing is selected it will launch the macro commands the entire line (ie cut the text across the line first)
Yes -- but since Obsidian already has you covered, regardless of selection, the above should still work.
If you are in Obsidian, "Cut" is always enabled -- the "If" action will "Do nothing"
If you aren't in Obsidian and "Cut" is enabled -- the "If" action will "Do nothing"
If you aren't in Obsidian and "Cut" is not enabled -- the "If" action will select the line
Whatever happens, the following "Type โX" should cut either the selection or the line.
"The line" may or may not be what you want, though. It will (usually) be a line as seen in the UI, not a line as in "the text between two linefeeds". If you want "the whole paragraph" you'll have to try some different keystrokes in your apps, but most "standard" Mac apps should accept โA to go to the start of the paragraph and โงโE to select from there to the end of the paragraph.
The value returned by the CLIPBOARDSEED() function changes every time the System Clipboard changes. So:
Put CLIPBOARDSEED() into a variable
Do your Cut (or Copy)
Test the current CLIPBOARDSEED() against the one you saved. If it's the same then the Clipboard wasn't changed -- you didn't Cut/Copy anything (or it's exactly the same as the last thing you Cut/Copied!)
thx so much again @Nige_S , really appreciate your kind help
this is cool to learn this method!
i created a macro (See below), which works 99% of the way. the only little thing remaining is that if there is a cut issues and the line is empty i want to execute a different set of commands. in obsidian seems like when i issue the โ+x, it still copies something and thus the CLIPBOARDSEED() seem to change
anyway around this?
here is the current macro based on your excellent input!
Can you check this? I'm seeing the opposite behaviour -- CLIPBOARDSEED() doesn't change and KM's %SystemClipboard% return the last-good value, even though the Clipboard is currently empty.
But if we test the Clipboard with AppleScript it returns the correct response. So if your version is doing as you describe, this might help:
You're doing a lot more than you need to, though. You've an unneeded extra "If" (if Obsidian isn't not at the front it must be at the front, no need to test again) and the same three actions in both branches of your "If" action -- the only difference between "Obsidian not at front, so execute...." and "otherwise execute..." are the two keystroke actions (the first of which has an unnecessary โง in it).
The advantage (besides better readability) is that if you want to change what is done between the Cut and Paste actions -- a different regex, or maybe some more transformations -- you only have to make the changes in one place. The disadvantage is that, being outside the "If" statement, the transformations will be applied whatever app is frontmost -- if you might want to do some things in most apps but some different things in Obsidian, leave it as it is.