Counting Lines in TextWrangler using Apple Script

192 views
Skip to first unread message

Krams R

unread,
Sep 28, 2017, 12:45:50 PM9/28/17
to TextWrangler Talk
How can I go about counting the number of lines in the current file using Apple Script?
I am also looking to move the cursor to the end of the file to add some additional content to the file.

I have tried endLine of document, text, window, selection etc. but I get errors about not being able convert endLine of <object> to type of endLine of <Object>
I tried using count of lines of <object> and get an error that says cannot get all the lines of <object>.
Trying count of line of <object> results in an error similar to the endLine usecase.

Thanks

Rich Siegel

unread,
Sep 28, 2017, 12:52:15 PM9/28/17
to textwr...@googlegroups.com
===

AppleScript is pretty flexible, and so there are often multiple
ways to accomplish something. Here is one:

tell application "TextWrangler"

-- returns the number of lines in the active text document
count of lines in text document 1

-- moves the insertion point to the end of the document
select the insertion point after the last character of text
document 1

end tell

===

R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <http://www.barebones.com/>

Someday I'll look back on all this and laugh... until they
sedate me.

Krams R

unread,
Sep 28, 2017, 1:44:29 PM9/28/17
to TextWrangler Talk
Rich,

Thank you for the help. Much appreciated. The last character of text document 1 works as desired.
Reply all
Reply to author
Forward
0 new messages