Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript Text Insertion at Cursor (Pages 6.3)

I would like to insert text at my cursor position in Pages 6.3 using AppleScript.


I found this subject that works with Pages 09' but this is obsolete with later versions of pages since it throw the error "Pages got an error: Can’t make content of selection into type specifier". (I tested myself with both versions to make sure it was working with 09' and it does)


I tried with Pages 6.3:

set selection to "test"

and tried:

set content of selection to "test"

None of them worked.

When I tried:

set C to characteroffsetof (get selection)


I got the error "Pages got an error: Can’t get selection."


Here is the full script:

tell application "Pages"


--set selection to "test"


--set content of selection to "test"


--set C to character offset of (get selection)

end tell


I can't find any documentation about selection anywhere, did anybody managed to write text at the cursor position with the latest version of Pages using AppleScript?


Thank you!

MacBook Air, macOS High Sierra (10.13.3), null

Posted on Feb 14, 2018 12:26 PM

Reply

Similar questions

12 replies

Feb 15, 2018 11:07 AM in response to adriendo

Many Pages v6.3.1 keyboard shortcuts can be found from:


Pages Help menu : Keyboard shortcuts : Pages for Mac keyboard shortcuts


tell application "Pages"

activate

tell front document

tell application "System Events"

keystroke "f" usingcontrol down-- one character forward

keystroke "b" usingcontrol down-- one character backward

keystroke "h" usingcontrol down-- delete previous character/selection

keystroke "d" usingcontrol down-- delete next character/selection

end tell

end tell

end tell

Feb 15, 2018 2:53 PM in response to adriendo

By definition, the selection will be replaced with whatever you type/keystroke.


Do you mean that you want to have the newly-inserted text selected at the end of the script?


If so, this may help:


set theStringToType to "blah blah blah"


tell application "Pages"


activate

tell application "System Events"


keystroketheStringToType

repeat (number of characters in theStringToType) times


keystroke "b" using {control down, shift down}

end repeat

end tell

end tell

It simply runs a number of 'cursor left' keystrokes with the addition of the shift key held down.

AppleScript Text Insertion at Cursor (Pages 6.3)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.