Sorry for the NOOB comments, I am now building up a Snippets DB so moving forward I will try to capture all my AppleScript chunks for my future review. I am not understanding some basic text manipulation skills. How do I tell the script to move the insertion point to a specific location? Position zero is the first insertion point but, how do I write this? All I can find is loads of examples about moving the cursor related to setting window positions. That is not what I am asking here.
In a Rich Text note within DevonThink, I am trying to keep a log of my progress on a certain project. I am also using Keyboard Maestro to either enhance using Applescript or at the very least, attach a keystroke command to execute the script.
What I want to do upon execution of the macro:
- move the insertion point to the top of the text, position zero,
- put in two returns
- Return the insertion point to point zero
- put in a date and time string ending with a colon and a space.
I can use a script example I just found on these forums to use AppleScript to tell TextExpander to expand the date and time - or if there is a way to use AppleScript to do this I can do that too.
Sorry but I just cannot find the example that shows me how to know where my insertion point is? I know I Have done this a long time ago. I just don’t use AppleScript everyday and I still find much about It obscure and hard to understand. Building my own version of logic in understanding the components of AppleScript moving forward might help.
Thanks for any help.
ADDED: Her is what I have been able to figure out so far. I still cannot get the insertion point to where I Want to start typing the new note. I don’t know if It is possible but if I could find the first instance of “:” and count two spaces that would be the ideal starting point for entering my new notes.
tell application id "DNtp"
try
tell selected text of window 1
set the_mon to month of (current date) as integer as string
if (count characters in the_mon) = 1 then set the_mon to "0" & the_mon
set the_day to day of (current date) as string
if (count characters in the_day) = 1 then set the_day to "0" & the_day
set the_date to the_day & "/" & the_mon & "/" & texts 3 thru 4 of (year of (current date) as string)
set timeStr to time string of (current date)
set Pos to offset of ":" in timeStr
set theHour to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string
set Pos to offset of ":" in timeStr
set theMin to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string
set Pos to offset of " " in timeStr
set theSfx to characters (Pos + 1) through end of timeStr as string
set the_date to (the_date & " " & theHour & ":" & theMin & " " & theSfx) as string
make new paragraph at beginning with data ((the_date) & ": " & return & return) with properties {alignment:justified, font:"Verdana", size:14, color:{5000, 5000, 5000}, background:{65535, 65535, 65535}}
end tell
end try
end tell