Select characters on both sides of insertion point
Posted: 2008-07-22 16:57:09
For use in a kerning macro, I need a way to select the two characters on opposite sides of the insertion point. The only solution I could figure out is the following, which seems rather complicated for such a simple task. Is there a simpler solution?
### Begin Macro: ###
$doc = Document.active
$selection = $doc.textSelection
If $selection.length == 0
$location = $selection.location
# Optionally insert here a test for insertion point at beginning of document.
$selection2 = TextSelection.newWithLocationAndLength ($doc.text, $location-1, 2)
$doc.setSelection ($selection2)
end
### End of Macro ###
# Optional commands to be inserted where indicated above:
If $location == 0
Prompt 'Error: Insertion point is at beginning of document.'
Exit
end
FYI, AppleScript has a fairly simple way to select the characters surrounding the insertion point:
tell application "System Events" to tell process "Nisus Writer Express"
key code 123 --left arrow
key code 124 using shift down --right arrow
key code 124 using shift down
end tell
### Begin Macro: ###
$doc = Document.active
$selection = $doc.textSelection
If $selection.length == 0
$location = $selection.location
# Optionally insert here a test for insertion point at beginning of document.
$selection2 = TextSelection.newWithLocationAndLength ($doc.text, $location-1, 2)
$doc.setSelection ($selection2)
end
### End of Macro ###
# Optional commands to be inserted where indicated above:
If $location == 0
Prompt 'Error: Insertion point is at beginning of document.'
Exit
end
FYI, AppleScript has a fairly simple way to select the characters surrounding the insertion point:
tell application "System Events" to tell process "Nisus Writer Express"
key code 123 --left arrow
key code 124 using shift down --right arrow
key code 124 using shift down
end tell