Need Help With Simple Text File Macro

Hi,

I have a simple macro that opens a text file and does a simple paste to the text file for temporary use.

For my use, I would like the text to always be pasted at the very top of the text file. The Applescript below seems to work ok using BBEDIT, however it fails using Apple TextEdit app.

The only problem with TextEdit app - is this line of Apple script fails (after the file is already open):

AS:
select insertion point before first line of front window

Q: - is there some better way to get the cursor to be at the very top of the document before pasting?

Example macro: --- simple macro ---

1- open text file temp.txt
2 - pause 1 sec
3 AS:

tell application "TextEdit"
activate
select insertion point before first line of front window
end tell

4 - insert text by pasting...


Thanks for your help - Dave

Hey @dealtek,

Here is one way to do it. However, you don't have to open TextEdit. If you want to, you can make the necessary adjustment.

Here is the macro:
Need Help With Simple Text File Macro.kmmacros (13.2 KB)

Here is the image of the macro

1 Like

I rely on a simple approach to this in my macros using two Type a Keystroke actions:

  1. Select All

  2. Up Arrow

That leaves the cursor at the top of the file in every application that takes text (even this text entry form).

I have a variety of AppleScripts to paste text into TextEdit and I’m glad to share some more info on them if you’re interested…however I wholeheartedly believe @kcwhat’s solution is best in this particular case. Because TextEdit is NOT AppleScript friendly.

-Chris

1 Like

Thanks much I will give it a try.

cool that is clever and simple.