This little template allows you the use of commands to create a CLI that works with applescript and TextEdit. I just thought I’d share it.
property Prompttxt : ""
property deftext : " version 1.0.0"
CLS()
repeat
set command to ""
set subcom to ""
set command to prompt(Prompttxt)
if command is "quit" then
exit repeat
else if command is "" then
else
display(command & " is not understood.")
end if
end repeat
on prompt(prompt)
set prompt to prompt & ": "
tell application "TextEdit"
set the text of the front document to the text of the front document & prompt
end tell
repeat
tell application "TextEdit"
set test to the text of the front document
end tell
if the last character of test is (ASCII character 10) then
exit repeat
end if
end repeat
set num to (the number of characters in prompt)
set endtext to strip(test, num)
return endtext
end prompt
on strip(theword, thenumber)
try
set StoreT to ""
set StoreN to the number of characters in theword
repeat with i from 1 to (StoreN - 1)
set StoreT to StoreT & character i of theword
end repeat
set command to the last paragraph of StoreT
set endtext to ""
repeat with i from thenumber + 1 to (the number of characters in command)
set endtext to endtext & character i of command
end repeat
return endtext
on error e
display dialog e
end try
end strip
on display(thetext)
tell application "TextEdit"
set the text of the front document to the text of the front document & thetext & return
end tell
end display
on show(datxt, prvtxt)
if prvtxt is "" then
tell application "TextEdit" to set prvtxt to the text of the front document
end if
return prvtxt & return & datxt & return
end show
on currenttext()
tell application "TextEdit"
return the text of the front document
end tell
end currenttext
on settext(datext)
tell application "TextEdit"
set the text of the front document to datext
end tell
end settext
on CLS()
tell application "TextEdit"
set the text of the front document to deftext & return
end tell
end CLS