Yvan,
merci encore pour votre temps et votre intérêt à m’aider à résoudre mon problème.
Mais, je me demande si vous voulez dire “ligne 5” dans votre script, puisque vous avez écrit:.
“I edited the script in message #5 to get rid of that.”
Heureusement, je reçu de l’aide du Japon … Il est pas un applescript, donc le peu que je sais sur Applescript ne me aide pas à comprendre sa structure. Mais il fonctionne parfaitement, car il me renvoie ce que je demandais (la deuxième question inclus) dans ma réponse précédente.
Je vous écris dans mon “terrible français”, et je suis désolé pour mes erreurs …
Ici vous trouverez le script japonais qui a fait ce travail. Je crois que est écrit en Python … et autre chose.
Thank you again for your time and your interest to help me solve my problem.
I wonder if you mean “line 5” in your script, since you wrote: “I edited the script in message #5 to get rid of that.”
Luckly, I received help from Japan … it is not an applescript, hence the little I know on Applescript doesn’t help me to understand its structure. But it functions perfectly, as it returns me what I was asking (the second question included) in my previous reply.
I write in my “terrible french”, and I am sorry for my mistakes …
Here you will find the japanese script which did this job. I believe is written in Python … plus something else.
The script:
set |NBSP| to character id 160 – U+00A0 NO-BREAK SPACE
set |NL| to linefeed – U+000A LINE FEED
–set dlm to |NBSP| & |NL| & “MOVIE” & |NL| & |NBSP| & |NL| – # delimiter pattern 1
set dlm to |NL| & “MOVIE” & |NL| – # delimiter pattern 2
set d to (choose folder with prompt “Choose output directory”)
set ff to (choose file of type {“rtf”} with prompt “Choose source rtf file(s)” with multiple selections allowed)
set args to dlm’s quoted form & space
repeat with a in {d} & ff
set args to args & a’s POSIX path’s quoted form & space
end repeat
do shell script "/usr/bin/python <<‘EOF’ - " & args & "
coding: utf-8
file:
split_rtf.py
usage:
split_rtf.py delimiter directory file.rtf [file.rtf …]
argv[1] : delimiter text
argv[2] : output directory
argv[3:] : source rtf file(s)
version:
0.11
import sys, os, re
from Foundation import *
from AppKit import *
argv = [ a.decode(‘utf-8’) for a in sys.argv ]
DLM = argv[1]
OUTDIR = argv[2]
DLML = len(DLM)
for f in argv[3:]:
mas, docattr, err = NSAttributedString.alloc().initWithURL_options_documentAttributes_error_(
NSURL.fileURLWithPath_(f),
{NSDocumentTypeDocumentOption : NSRTFTextDocumentType},
None,
None)
if not mas:
sys.stdout.write(‘%s: failed to read rtf: %s\n’ % (f.encode(‘utf-8’), err.description().encode(‘utf-8’)))
continue
s = mas.string()
aa = s.componentsSeparatedByString_(DLM)
k0 = aa[0].length() + DLML
for a in aa[1:]:
k = k0
k0 += a.length() + DLML
m = re.search(r'^(.*) Last Seen:', a, re.M)
if not m: continue
n = m.group(1)
n = re.sub(r':', ';', n) # replace : with ; (: in file name is shown as / in OS X Finder)
n = re.sub(r'/', ':', n) # replace / with : (/ is reserved as node separator in POSIX path)
outfile = os.path.join(OUTDIR, '%s.rtf' % n)
data = mas.RTFFromRange_documentAttributes_(
(k, a.length()),
docattr)
b = data.writeToFile_atomically_(
outfile,
False)
if not b:
sys.stdout.write('%s: failed to write file: %s\\n' % (outfile.encode('utf-8'), err.description().encode('utf-8')))
EOF"
Kind regards
Danwan