System events are certainly the easier (shorter) way to do it: --- tell application "BBEdit" to tell front window activate tell application "System Events" to keystroke end tell application "System Events" to keystroke return tell application "System Events" to keystroke tab end tell ---
Here is at least one way to do it with just BBEdit's capabilities: --- tell application "BBEdit" to tell front window set lineNum to startLine of selection set leng to length of line lineNum -- Move cursor to end of line if leng > 0 then select insertion point after (character (leng) of line lineNum) end if -- Find leading whitespace set theResult to find "(^[\\s]*)" options {search mode:grep} searching in line (lineNum) -- Set text to the white space found set white to "" if found of theResult then set white to found text of theResult end if -- Add extra indent set white to white & tab -- Insert a return plus the white space set selection to return & white select insertion point after selection end tell --- I assumed you were using tabs for indentation. A little surprisingly, the BBEdit way executed quicker. The system events way also has issues if you're holding down any modifier keys (e.g., command, control) as those keys will be attached to the system events when it does the keystroke. Not so great. I haven't thoroughly tested either solution FYI. -Kendall On Jan 18, 5:31 pm, Watts Martin <lay...@gmail.com> wrote: > I'm working on a little AppleScript that replicates a trivial but > cherished feature of another editor -- being able to press Ctrl-Return > (or whatever) and having it start the new line with an appropriate > indent. > > My script does the right thing now as long as there's nothing on the > line below where it's executed, but what I'd really like to have > happen is the equivalent of the Open Line, i.e., when you invoke the > script at the end of a line that's followed by another one, the second > line is moved down: > > text here > | > text here > > Since my script currently just inserts a return followed by the > appropriate number of spaces or tabs to indent one tab stop past the > start of the line it was invoked on, it makes a cheerful mess of > things in this case. Using Open Line would be much better, I suspect > -- but I can't figure out how to do so from the dictionary alone. Is > there a way to actually invoke the Open Line command with BBEdit's > dictionary, or do I need to go through System Events to pull this off? -- You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups. To post to this group, send email to bbedit@googlegroups.com To unsubscribe from this group, send email to bbedit+unsubscr...@googlegroups.com For more options, visit this group at <http://groups.google.com/group/bbedit?hl=en> If you have a feature request or would like to report a problem, please email "supp...@barebones.com" rather than posting to the group. Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>