Page 1 of 1

insert a discretionary return

Posted: 26 Nov 2018, 18:29
by chandlerbing
I've been trying for hours to find even the basic information I need to make this script, and just can't come up with it. Is it possible to create an applescript that will replace every instance of "/" in my selected text with the slash plus a discretionary return (option-\)?

Re: insert a discretionary return

Posted: 27 Nov 2018, 03:21
by Jean-Marie Schwartz
Hi! Give this a try:

Code: Select all

property DiscRet : character id 7 --«data utxt0007» as Unicode text -- U+0007; 7

tell application "QuarkXPress9"
	tell document 1
		tell story 1 of current box
			set every text where it is "/" to DiscRet
		end tell
	end tell
end tell
HTH.

Re: insert a discretionary return

Posted: 27 Nov 2018, 12:45
by chandlerbing
Thanks. That's closer, but not quite what I need. I need to keep the slash and also have a discretionary return. This version (below) using the unicode you provided works except it's using soft returns, not discretionary returns. I can't find the correct code for a discretionary return or I think it would work. (BTW, in my original post I typed the WRONG keystroke for the discretionary return. Brain fart. I meant command-return for the discretionary return)

property DiscRet : character id 7 --«data utxt0007» as Unicode text -- U+0007; 7

tell document 1 of application "QuarkXPress"
tell selection
set every text where it is "/" to "/" & DiscRet
end tell

end tell

Re: insert a discretionary return

Posted: 27 Nov 2018, 13:15
by chandlerbing
I think I figured it out. With a bit more research I discovered that the discretionary return in Quark is technically a "zero-width space." Found the code for that and this script now works.

Code: Select all

tell document 1 of application "QuarkXPress"
	tell selection
		set every text where it is "/" to "/" & {character id 8203}
	end tell
	
end tell

Re: insert a discretionary return

Posted: 28 Nov 2018, 05:17
by Jean-Marie Schwartz
Sorry for the misunderstanding.
Wonderful how you dealt with it! Congrats and enjoy!