Applescript: Selecting a line of text at the cursor

I’m sure this is painfully obvious but right now it’s completely eluding me. I’m trying, from an Applescript, to select the full line of text that the cursor or selected text is currently placed. Is that possible at all?


I’d probably tell the text to get the paragraph at the current selection, and then parse the paragraph. You didn’t define “the full line of text” – but I assume that means the text of the current paragraph. Perhaps if you could tell us a little more about what you’re trying to accomplish?

You’re right, it would be the paragraph. I just want a quick way to set title styles. H1, H2 kInd of thing. OS x styles are woeful so I’m using a Quickeys hot key to trigger a script that sets font size and colour. I figured I could save myself some time by having the script do the selecting for me.

Please feel free to talk to me like I’m an idiot, by the way. At least in all things OSX scripting. I’m pretty good with most languages but Applescript and I operate in an environment of mutual disrespect which is sometimes unhelpful.


So maybe have Quickeys do command-left-arrow then shift-down-arrow to move the cursor to the head of the line and then select the line?

You beat me to the post, here’s my solution:-

Firstly, Quickeys is a mess in 10.7, officially incompatible, no real news on it ever being, so I’ve switched to a Keyboard Maestro, again with a hotkey triggering it. One ctl-shift-left arrow action and one ctl-shift-right arrow then applescript as below. No need to activate Devonthink, it’s already there. When I get some spare time I’ll change it to use the frontmost application, make it a bit more general, maybe. And thanks for you help.

tell application “DevonTHINK Pro”
tell selected text of the front window
set font to “Arial”
set size to 18
set colors to {35000,35000,35000}
end tell
end tell