on install_dico(nom, nommodifie, chemin)
try
do shell script "cp " & nom & " " & chemin & nommodifie
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
end try
set liste to every word of nom as list
set nomcourt to item -2 of liste & "-" & item -1 of liste
return nomcourt
end install_dico
on findAndReplace(tofind, toreplace, TheString)
set ditd to text item delimiters
set text item delimiters to tofind
set textItems to text items of TheString
set text item delimiters to toreplace
if (class of TheString is string) then
set res to textItems as string
else
set res to textItems as Unicode text
end if
set text item delimiters to ditd
return res
end findAndReplace
on modifie_nom(nomdico)
set nom_modifie to findAndReplace("-fr-fr", "-fr", nomdico)
return nom_modifie
end modifie_nom
set chemincustom to "/Volumes/KOBOeReader/.kobo/custom-dict/"
set cheminbase to "/Volumes/KOBOeReader/.kobo/dict/"
try
do shell script "ls " & chemincustom
on error the error_message number the error_number
display dialog "Erreur " & the error_number & " : aucune Kobo connectée, merci d'en connecter une !" buttons {"Quitter"} default button 1
return
end try
display dialog "Sélectionner le fichier dictionnaire (ex: dicthtml-fr-fr.zip)"
set nomdico to (choose file)
set dico to "\"" & POSIX path of nomdico & "\""
set liste to every word of dico as list
set val to (count of liste)
set nomcourt to last item of liste
set listelettres to every character of nomcourt as list
set extension to item -3 of nomcourt & item -2 of nomcourt & item -1 of nomcourt
if extension is not "zip" then
display dialog "Le fichier doit être un fichier zip" buttons {"Quitter"} default button 1
return
end if
set nomdicocourt to item -3 of liste & "-" & item -2 of liste & "-" & item -1 of liste
display dialog "Souhaitez-vous installer \"" & nomdicocourt & "\" :
1) uniquement comme dictionnaire perso ?
2) ou également comme dictionnaire de base Kobo ? " buttons {"1", "2", "Annuler"} default button 3
set the button_pressed to the button returned of the result
set Info to ""
set InfoS to ""
if the button_pressed is "Annuler" then
return
else if the button_pressed is "2" then
set nommodifie to modifie_nom(nomdicocourt)
set Info to " & " & install_dico(dico, nommodifie, cheminbase)
set InfoS to "s"
end if
set nomcourt to install_dico(dico, "", chemincustom)
display dialog "Dictionnaire" & InfoS & " " & nomdicocourt & Info & " installé" & InfoS buttons {"Quitter"} default button 1