set monfichier to choose file with prompt "Sélectionnez le fichier contenant les hyperliens"
set Chemin to choose folder with prompt "Sélectionnez le dossier recvant les webloc"
open for access monfichier -- ouvre ce fichier en lecture
set vartoto to read monfichier -- lit le fichier et le met dans la variable vartoto
close access monfichier -- ferme le fichier
set hyp to "HYPERLINK"
set guil to (ASCII character 34)
set occu to hyp & " " & guil
set avant to "<?xml version=" & guil & "1.0" & guil & " encoding=" & guil & "UTF-8" & guil & "?>
<!DOCTYPE plist PUBLIC " & guil & "-//Apple//DTD PLIST 1.0//EN" & guil & " " & guil & "http://www.apple.com/DTDs/PropertyList-1.0.dtd" & guil & ">
<plist version=" & guil & "1.0" & guil & ">
<dict>
    <key>URL</key>
    <string>"
set apres to "</string>
</dict>
</plist>
"
repeat
    set vartoto to vartoto as string
    set aa to offset of occu in vartoto
    if aa = 0 then exit repeat
    set nb to aa + 11
    set lelien to ""
    repeat while character nb of vartoto is not guil
        set lelien to lelien & character nb of vartoto
        if (character nb of vartoto) = "&" then
            set lelien to lelien & "amp;"
        end if
        set nb to nb + 1
    end repeat
    
    set vartoto to characters nb thru -1 of vartoto
    set ccc to vartoto as string
    
    set chemindef to (Chemin & "liste des liens.txt") as text
    set lefichier to open for access chemindef with write permission
    write lelien & return to lefichier starting at eof
    close access lefichier
    
    
    set unlien to avant & lelien & apres
    set nbcaractere to count characters of lelien
    if nbcaractere > 200 then
        set lelien to characters 1 thru 200 of lelien as string
    end if
    set lenom to characters 9 thru -1 of lelien as string
    tell application "TextEdit"
        set lenom to lenom & ".webloc"
        set chemindef to ((Chemin as text) & lenom) as text
        try
            set lefichier to open for access chemindef with write permission
            set eof lefichier to 0 -- pour effacer le fichier existant
            write unlien & return to lefichier starting at eof
            close access lefichier
        on error e
            display dialog "Le fichier «lien X.webloc n'a pu être créé" & return & return & "Verifiez que le repertoire existe et qu'il a des droits en écriture" with icon 0 buttons "Annuler" default button 1
        end try
    end tell
end repeat
tell application "Finder"
    activate
    (display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell