Using AppleScript to find straight quotes and replace with curly quotes

I receive various Word documents for proof-reading which have a mixture of straight quotes and curly quotes (must be Windows-based documents as I am not sure how they achieve that, given that Word on a Mac has the option to replace straight quotes with curly quotes). I signal changes using track changes. The ASCII/ANSI code for a single straight quote is 39 and typing ^39 into find and ’ into replace works well. I can build a macro which carries out the same function. Although I have AppleScripts to find and replace, for example, double paragraph marks with single paragraph marks, I cannot formulate an AppleScript to do the same task: using
execute find (find object of myRange) find text “^39” replace with “'” replace replace all
does not work.
Anyone able to offer any help?

How would the script determine which curly quote to use?

Hello
Your question is vague , but if I understand its purpose, this just a frame of script to give you a hint,
assuming you get the text to modify from the clipboard

set theText to the clipboard

set text item delimiters to "\""
set theTextItems to theText's every text item
set text item delimiters to "’"
set theText to theTextItems as string
set text item delimiters to ""
return theText

then it’s up to you to use this in a convinient way for what you expect.
Hope this helps

Try the following:

property a : character id 8216
property b : character id 8217

tell application id "MSWD"
	activate

	set selFind to find object of selection
	execute find selFind find text "^w^39" replace with (space & a) replace replace all wrap find find continue with match forward
	execute find selFind find text "^39^w" replace with (b & space) replace replace all wrap find find continue with match forward
	execute find selFind find text "^39" replace with b replace replace all wrap find find continue with match forward

	
end tell

Just make sure the Prefix and Suffix options are not checked in the Find and Replace Word dialog: they can’t be modified by script.

1 Like

Thank you all for your help. Jonah’s solution works perfectly and has helped me to write a script which solves my problem. Most grateful to you all for taking the time.