Copy a line of text

I know this is pretty frigging basic but I can’t seem to get it to happen. I keep getting funky errors whenever I try to get a line of text or a specific word, etc.

What I’m trying to do is tell applescript to set a parameter to a line of text from BBEdit.

I need to do this so that I can get the last one or two characters from that line of text. But I’ve tried things like set bob to line 1 of window 1 and that doesn’t work…I can’t seem to get it to select a specific line so that I can copy and / or paste it either…

So how can I grab a specific line of text (or even a specific word or character) from a text document opened with BBEdit?

That will depend on the version of BBedit your using, becuase each version updates the dictionary. Here is a sample from an X version that searches for duplicate lines of text and then deletes in a BBedit file:

--by Nigel Heinsius
tell application "BBEdit 6.1 for OS X"      
	set countNum to {count lines of window 1}
	repeat with i from 1 to countNum
		if (line i exists) then      
			«event R*chGoto» i -- Make your changes here to suit your "search"
			select line i
			set currentOne to contents of selection
			repeat while («event R*chFind» currentOne without «class Top » and «class Grep»)--probably use a "repeat until" here to find your string
				«event R*chRepl» given «class RplS»:""
			end repeat
			exit repeat
		end if
	end repeat
end tell

Anything inside of << >> is syntax that OS 9 doesn’t understand. I hope the routine helps to modify it for 9.

Thanks, I got it…finally.

My problem was that I did not have the “select line 1 of window 1” command within the tell application command so it was (I assume) defaulting to the finder when trying to select the line.

It’s all good now though :slight_smile: