Hallo Martin,
ein interessantes Problem. Die Lösung ist: Der String muss in eine Liste verwandelt werden. Und
zwar nicht buchstabenweise, sondern immer sechs Zeichen. Dabei sind aber die Wortzwischenräume
"Störenfriede". Ich schlage vor, diese ebenfalls im Unicode-Format einzusetzen und zwar mit
Hilfe der 'text item delimiter':
---
set myOldText to "<05E1><05E4><05E8> <05D9><05E6><05D9><05E8><05D4>"
set AppleScript's text item delimiters to {" "}
set tmpList to every text item of myOldText as list
set AppleScript's text item delimiters to {"<0020>"}
set myOldText to every text item of tmpList as string
set AppleScript's text item delimiters to {""}
myOldText
-->"<05E1><05E4><05E8><0020><05D9><05E6><05D9><05E8><05D4>"
Dann kann man eine leere Liste definieren und mit einer Repeat-Schleife im Sechserschritt
die Element daran anfügen:
---
set aList to {}
repeat with i from 1 to (count of myOldText) by 6
set end of aList to text i thru (i + 5) of myOldText
end repeat
aList
-->{"<05E1>", "<05E4>", "<05E8>", "<0020>", "<05D9>", "<05E6>", "<05D9>", "<05E8>", "<05D4>"}
Im Ergebnis kann man die Reihenfolge umkehren und wieder zurück in einen String verwandeln:
---
set revList to (reverse of aList) as string
-->"<05D4><05E8><05D9><05E6><05D9><0020><05E8><05E4><05E1>"
Soviel zur Theorie. Umgesetzt in Dein Script könnte es etwa so aussehen:
---
tell application "InDesign CS"
set myOldText to selection as string
set myNewText to my theConversion(myOldText)
set contents of selection to myNewText
end tell
on theConversion(myText)
set AppleScript's text item delimiters to {" "}
set tmpList to every text item of myText as list
set AppleScript's text item delimiters to {"<0020>"}
set myText to every text item of tmpList as string
set AppleScript's text item delimiters to {""}
set myList to {}
repeat with i from 1 to (count of myText) by 6
set end of myList to text i thru (i + 5) of myText
end repeat
set myNewText to (reverse of myList) as string
end theConversion
---
Wie Du siehst, habe ich die Schreibweise der Variablen Deinem Muster angepasst. Ich habe
aber grosse Mühe mit all diesen 'my' und 'the'. Gut, ich weiss, dass _sämtliche_ InDesign-Scripts
in diesem Stil geschrieben sind. Leider.
Ich bin nicht sicher, ob dieses Script funktioniert, denn ich habe es nicht ausprobiert. Dies
überlasse ich gerne Dir …
Hans Haesler <hsa@ringier.ch>
als Antwort auf: [#419120]