Place Cursor

OOPS! Sorry, I hadn’t read your idea and let It sink In. Yes, hitting the command and up arrow will work. Thanks, (Still curious if the pipe example can be modified though)

[quote=“levelbest, post:1, topic:1698, full:true”]I was asked if I could include a screen shot but I am not sure if that is needed? Just put the cursor in any text field, hit the up arrow until you are on the top line. Then hit the left arrow until you are as far to the left as you can go. This is position 0,0. I am asking how to tell a KM macro to start from that point, no matter where the cursor was when the macro was triggered. This assumes that you are already active in a text field of course and the cursor was already in the text field … Somewhere.

There is a pipe example (%|%) in the typing of text as opposed to pasting the text. Using this It will move the cursor only to the start of whatever line It started in.

I need It to go to the upper left or position 0,0 in the text area the cursor is in.
[/quote]

Have you tried:
Click anywhere in the text field
CMD + UpArrow

That should take you to the start of the first line in the field.

Yes, that is what I had done in the earlier thread. I placed the cursor in the upper left before triggering the macro. Then two returns and two up arrows and the new entry begins.

What I am asking here is, if there is a more elegant solution? It would be more efficient if, when I triggered the macro for a new date and a new entry, I could trigger It from anywhere in the field.

All in all not that big a deal but, It also teaches me more about how KM works.

In the KM macro, issue the “Type a Keystroke” action.

1 Like

@levelbest, you might find this helpful:
Getting Started [Keyboard Maestro Wiki]

@peternlewis may have other suggestions.

Thanks but I think we are not in sync here. Please see my top post. Your suggestion to use option and up arrow as a keystroke did the trick.

I always appreciate learning tips as well.

Thanks.

I assume you meant CMD + UpArrow.

My keyboard is Microsoft split keys and It is not labeled correctly so … Yes. The one that did the trick. CMD

Hey levelbest,

You have to realize that Apple does not provide public APIs to everything OSX does under-the-hood.

Peter uses all that’s public and stays away from hacks that will surely break.

Text fields are not universally available to an API (application program interface), so you can’t just magically manipulate text everywhere.

On the other hand some apps are directly scriptable, and some are very amenable to manipulation via System Events.

In the case of any-text-field the only thing you can do is manipulate (brute-force) the OSX UI. Therefore simulated keystrokes like Michael has described can work well if UI elements are stable enough and/or predictable enough.

If you want real control over an app then you need something highly scriptable like TextWrangler or BBEdit.

DevonThink is pretty scriptable, but I’d have to look at it to see how well it handles scripting text.

Run this script to get an idea of what is possible.

------------------------------------------------------------
# TextWrangler
# Example of creating a log file (if not existing),
# and writing log entries to it in LIFO order.
------------------------------------------------------------
set myLogFile to "~/Desktop/My Log File.txt"

if myLogFile starts with "~" then set myLogFile to (POSIX path of (path to home folder as text)) & text 2 thru -1 of myLogFile
try
  alias POSIX file myLogFile
on error
  do shell script "touch " & quoted form of myLogFile
end try
set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set myLogFileName to last text item of myLogFile
set AppleScript's text item delimiters to oldTIDS

tell application "TextWrangler"
  activate
  if text window myLogFileName exists then
    set logFileWin to text window myLogFileName
    if logFileWin's index ≠ 1 then set logFileWin's index to 1
  else
    open myLogFile
  end if
  tell text window myLogFileName
    if bounds ≠ {0, 45, 614, 647} then set bounds to {0, 45, 614, 647}
    set before text of line 1 to my dateStamp(current date) & return & return
    select insertion point before character 1
  end tell
end tell

on dateStamp(_date)
  return _date as «class isot» as string
end dateStamp
------------------------------------------------------------

-Chris

[Edited 2015/07/29 23:56 CST to fix make window bounds work on any screen size.]

I am getting to the same idea across multiple threads so It is getting a bit confusing here. All of the questions I have been asking and all of the threads are about the same thing, getting some text copied out of some selected text and using a specific text-editor or text processor to work with KM Macros to alter that text and then to return the text. This would include spell checking, re-pasting, entering a date, styling the date string, etc. I tend to think in terms of projects or big picture so I tend to jump sideways in threads, not meaning any harm but probably causing some confusion of my own. Solutions of course are in the details of the discussions. Ah, well …

I got an error that AS could not get bounds of log file.

TW seems not friendly to style as in, It’s a text editor. What I write in a forum post can get quickly spell checked and returned with no loss of style because the forum page runs css or whatever to determine the text appearance. TW would work with that sort of thing quite well.

TW seems less than interested to these styling clues. What I write in DTPO or Bean uses visual styling cues, indents, colors, paragraph spacing. I like style. I like seeing formatting in what I write, even a time stamp for an event.

The only problem I am having with Bean is that I am putting a conditional into my KM macro since I don’t want my spell checker to affect any already open document I am editing with Bean. Thanks to Kms fantastically well thought out environment, I can do this quite easily.

I fixed the script, so it should run for you now.

-Chris

I suggest you save a document somewhere named something like ‘Spell_Check_Doc.rtf’.

That gives you a reference to use with Keyboard Maestro for spell-checking, which in my opinion is better than fooling with untitled windows.

In pseudocode:

Your first macro:

Copy text where you are working.

If application Bean is running
    Set value of variable beanIsRunning to TRUE
else
    Set value of variable beanIsRunning to FALSE
end if

Open document ~/Library/Application Support/Keyboard Maestro/KM Support Files/Spell_Check_Doc.rtf

Paste

Your second macro:

If variable beanIsRunning is TRUE
    Select-All
    Cut
    Save
    Close Window
Else If variable beanIsRunning is FALSE
    Select-All
    Cut
    Execute AppleScript Action: 
        tell application "Bean"
            quit without saving
        end tell
end if

Make certain your original app is in front for safety.
paste

-Chris