Script to select the paragraph where the cursor is located.

Hello.

tell application “System Events”
set theName to name of the first process whose frontmost is true
end tell

tell application “System Events”
tell process theName
delay 0.2
click
click
click
end tell
end tell

Objective: Select the paragraph in which the cursor is located.

I don’t know of any key combination that does the function of selecting a paragraph.

In the predefined voice commands for the mouse there is “triple click” which, applied to text, selects the paragraph where the cursor is located.

The script above pretends to simulate “triple clicking”, but it is not successful.

Any ideas?

I appreciate any help.

Slightly separate from standard ui scripting, Voiceover has a scripting dictionary which includes a click thrice command.

Alas but documentation is non-existent and there are only the barest examples of any voiceover scripts that I could find.

If you run the following with voiceover on, then the script might switch to safari and triple-click a random spot on the page. Sorry, but I don’t have any useful advice on how to control it. This is disappointing, especially since it seems to have a fairly extensive command set.

use application "VoiceOver"
tell application "Safari"
	activate
	tell commander
		perform command "move mouse pointer to voiceover cursor"
		delay 1
	end tell
end tell
output mouse summary
tell mouse cursor
	click thrice
end tell
end

Hi,

You should use real mouse clicks at current mouse position with some mouse tool or with following AsObjC. Enable Voice Over, put mouse on some line of script, then run script using keyboard shortcut Command+R. Or, make it Automator Service:


use AppleScript version "2.4" --max version macOS 10.12
use scripting additions
use framework "Foundation"
use framework "ApplicationServices"
use framework "Quartz"
use framework "AppKit"
property updateMouseCursorPosition : true
property buttonCount : 1 -- left mouse button number
property mouseButtonDown : true -- mouse button pressed?

set aPoint to getCurrentMousePosition() -- get current cursor position on screen

mouseLeftClick at aPoint -- perform left click and move the cursor to new position
mouseLeftClick at aPoint -- perform left click and move the cursor to new position
mouseLeftClick at aPoint -- perform left click and move the cursor to new position


on getCurrentMousePosition()
	-- Getting the screen resolution and the bottom bound
	tell application "Finder" to set screen_resolution to bounds of window of desktop
	set theBottom to item 4 of screen_resolution
	-- Getting current mouse position {0,0} is top left corner of screen
	set currentMousePosition to (current application's NSEvent's (mouseLocation)) as record
	set x to currentMousePosition's x as integer
	set y to theBottom - (currentMousePosition's y) as integer
	return {x, y}
end getCurrentMousePosition


on mouseLeftClick at aPoint
	current application's CGPostMouseEvent(aPoint, updateMouseCursorPosition, buttonCount, mouseButtonDown)
	current application's CGPostMouseEvent(aPoint, updateMouseCursorPosition, buttonCount, not mouseButtonDown)
end mouseLeftClick

Hi Mockman

Thanks for answering my question.

I have copied the code you suggest and I have not been able to get information that can help me execute the triple click with the mouse that is capable of selecting the paragraph in which the cursor is located.

The absence of results does not detract from my sincere thanks.

Hello KniazidisR

Thank you very very much.

Your code to make a triple click with the mouse button at the cursor position is a success and perfectly meets my needs.:smiley: :smiley: :smiley:

The comments that you have added to the code, along with the attempts to find information about NSEvent and CGPostMouseEvent (a totally new world for me) have made it possible that, at least partially, I have understood the structure of your script which has given me great satisfaction.

My sincere thanks again for the help given with your time and your knowledge that have achieved an excellent result.

Greetings.

Hi Fredrik71

First of all express my thanks for answering my question. :slight_smile: :slight_smile: :slight_smile:

Your script works perfectly to achieve the goal of simulating mouse click and I am surprised by the small number of lines of code required.

My low level of knowledge in AppleScript has not allowed me to understand and keep track of the action of each of the lines that compose it, despite having sought information about the resources you have used that are of an unattainable level at the moment current for me.

For that reason I would ask you to comment, even briefly, on each of the lines that make up the script; your comments would help me understand its structure.

Thanks again for your help.