 |
Forum Avosmac - MacDebrouille Le forum du magazine Avosmac, trucs et astuces pour Macintosh
|
| Voir le sujet précédent :: Voir le sujet suivant |
| Auteur |
Message |
ndubau
Inscrit le: 20 Nov 2006 Messages: 8
|
Posté le: Ven 08 Mai 2009 16:53:08 Sujet du message: Applescript de conversion Appelworks vers Word (doc ou rtf) |
|
|
Bonjour,
J'ai une grande quantité de notes de lecture rédigées sous Appleworks ; bien entendu je sais via enregistrer sous les rendre utilisables dans OpenOffice ou Word.
Mais quand cela se compte par milliers le Fichier / Ouvrir / enregistrer sous... est lassant !
Qui aurait commis ou connaitrait un applescript permettant d'automatiser cette tâche : on désigne le dossier et tous ce qui est de type CWPP et ouvert et ré enregistré en .rtf ou .doc
Merci de votre intérêt
Noël |
|
| Revenir en haut de page |
|
 |
Didier Gross
Inscrit le: 13 Jan 2008 Messages: 2470
|
Posté le: Dim 31 Mai 2009 13:39:34 Sujet du message: |
|
|
Bonjour,
Il suffit de lancer une recherche sur google de "applescript applework convert" pour tomber très vite là-dessus:
http://lists.apple.com/archives/Automator-users/2007/May/msg00003.html
Dis-nous si tu t'en tires à partir de cette base. Désolé, c'est en anglais. _________________ Cordialement,
Didier Gross
---------------
Jusqu'à récemment, utilisateur Apple par choix.
Aujourd'hui, utilisateur Apple parce qu'ailleurs, c'est pire… |
|
| Revenir en haut de page |
|
 |
ndubau
Inscrit le: 20 Nov 2006 Messages: 8
|
Posté le: Mer 05 Aoû 2009 15:23:03 Sujet du message: |
|
|
Je ne sais par quelle facétie du temps et/ou de la technologie cette réponse ne m'apparaît qu'aujourd'hui !
Mais je ne voudrais pas passer pour un gros mufle impoli ! Merci de ce lien. J'avais trouvé entre temps ce travail
| Code: | --[SCRIPT AW batch BOBO2Office8]
(*
Exécuter ce script ou déposer l'icône d'un dossier
sur son icône (version application)
ouvre les documents AppleWorks du dossier
et les enregistreSous en fichier Office
dans le dossier "wasBOBO_nowOffice" sur le bureau.
Run the script or drag and drop a folder icon
on its icon (application version)
open AppleWorks documents stored
in the folder and save them as Office file
in the folder "wasBOBO_nowOffice" on the desktop.
Yvan KOENIG le 11 juin 2004
modifié le 12 juin 2004
étendu le 13 juin 2004
modifié le 14 juin selon suggestions de Hiroto TAOKA
traité bug AW6, (merci Hiroto) le 15 juin 2004
modifié le 17 juin 2004
modifié le 18 juin 2004
modifié le 19 juin 2004
modifié le 25 novembre 2004
modifié le 3 décembre 2004
modifié le 8 août 2008 (problème Mac OS X 10.5. Merci Hiroto)
*)
property englishMsg : true (* false = messages français
? true = english messages *)
property drelin_drelin : true (* false pour éviter le signal sonore *)
property Stockage : "wasBOBO_nowOffice"
property extensionWP : ".doc" -- globale
property extensionSS : ".xls" -- globale
property extensionDB : ".doc" -- globale
property extensionGR : "" -- globale
property rapport : "" -- globale
property msg0 : "" -- globale
property msg1 : "" -- globale
property msg5 : "" -- globale
property msg7 : "" -- globale
property msg8 : "" -- globale
property msg91 : "" -- globale
property msg92 : "" -- globale
property msg93 : "" -- globale
property msg94 : "" -- globale
property msg95 : "" -- globale
property msg96 : "" -- globale
property msg97 : "" -- globale
property msg98 : "" -- globale
property msg99 : "" -- globale
property NoTranslation : "" -- globale
property traducteurWP : "" -- globale
property traducteurSS : "" -- globale
property traducteurDB : "" -- globale
property traducteurGR : "" -- globale
property cheminDeStockage : "" -- globale
property nbDocsOuverts : 0 -- globale
property Bttns1 : {"", "", ""} -- globale
property listeGraphiques : {}
-- ===========
(* deux lignes exécutées si on double clique
sur l'icône du script application
? two lines executed if one double click
the application script's icon *)
if englishMsg is true then
set msg00 to "Choisir un dossier ?"
else
set msg00 to "Choose a folder ?"
end if
tell application "Finder"
choose folder with prompt msg00
set listeFichiers to every item in result
end tell
if (count of listeFichiers) = 0 then return
open listeFichiers
-- ==============================
on open (sel) (* sel contient une liste d'alias des éléments
qu'on a déposés sur l'icône du script (la sélection)
? sel contains a list of aliases of the items
dropped on the script's icon (the selection) *)
try
if msg0 is "" then my prepareMessages()
set {rapport, listeGraphiques} to {"", {}}
tell application "AppleWorks 6"
if "6." is not in (version as text) then ¬
error msg0 number 8000
set nbDocsOuverts to (count each document)
end tell -- to AppleWorks
set traducteurs to my construitListeTraducteurs()
repeat
tell application (path to frontmost application as string) to ¬
set dd to (display dialog ("WP - " & traducteurWP & return & ¬
"SS - " & traducteurSS & return & ¬
"DB - " & traducteurDB & return & ¬
"GR - " & traducteurGR) ¬
buttons Bttns1 with icon 1)
if dd's button returned is Bttns1's item 1 then ¬
error number -128
(* On a cliqué Annuler/Cancel
utile si on exécute en messages français sur un système anglais.
? Click was on Annuler/Cancel
useful if englishMsg messages are used on an english OS *)
if dd's button returned is Bttns1's item 3 then ¬
exit repeat (* Modifier/Reset *)
(* ici si bouton 2 (Modifier)
? Here if button 2 (Reset) *)
set {tradWP, tradSS, tradDB, tradGR} to ¬
{{NoTranslation}, {NoTranslation}, ¬
{NoTranslation}, {NoTranslation}}
repeat with tr in traducteurs
if tr contains "WORD" then
set end of tradWP to tr
else if tr contains "EXCEL" then
set end of tradSS to tr
else if tr contains "ASCII" then
set end of tradDB to tr
else if ((tr contains "JPEG") and not (tr contains "2000")) ¬
or (tr contains "TIFF") then
set end of tradGR to tr
end if
end repeat -- with tr
set traducteurWP to my quelTraducteur(tradWP, msg95, traducteurWP)
set traducteurSS to my quelTraducteur(tradSS, msg96, traducteurSS)
set traducteurDB to my quelTraducteur(tradDB, msg97, traducteurDB)
set traducteurGR to my quelTraducteur(tradGR, msg98, traducteurGR)
end repeat
if traducteurGR contains "TIFF" then
set extensionGR to ".tif"
else if (traducteurGR contains "JPEG") then
set extensionGR to ".jpg"
end if
set cheminDeStockage to my creeDossierDeStockage()
repeat with elem in sel
set elemA to elem as alias -- NOUVEAU
my exploreTraite(elemA, (info for elemA), "")
end repeat
tell application "AppleWorks 6"
activate
if listeGraphiques is not {} then
set traducteurs to my construitListeTraducteurs()
(* indispensable *)
if drelin_drelin is true then beep 3
(* signale qu'il faut intervenir pour fichiers graphiques
? claims that the user must click for graphic documents *)
repeat with descripteur in listeGraphiques
set {leFichier, leTraducteur, nouveauChemin} ¬
to descripteur
open alias leFichier (* pas besoin de "try", celà a déjà fonctionné
? no need to "try", already worked at first attempt *)
my enregistreSous(leFichier, leTraducteur, nouveauChemin)
close document 1 without saving
end repeat
end if -- listeGraphiques?
if rapport > "" then ¬
make new document with data ¬
(msg8 & return & return & rapport)
end tell -- to AppleWorks
on error MsgErr number NroErr
if NroErr is not -128 then
beep 2
tell application ¬
(path to frontmost application as string) to ¬
display dialog "" & NroErr & " : " & MsgErr ¬
with icon 0 ¬
buttons {msg99} giving up after 20
end if -- NroErr is?
return
end try
end open
-- ============= Routines
on creeNomUnique(dossier_, nom_, extension_)
set {suffixe, i} to {extension_, 1}
set {laFin, chemin_} to {suffixe, ""}
repeat
try
set chemin_ to "" & dossier_ & nom_ & laFin
chemin_ as alias (* un fichier de même nom existe-t-il ?
si oui (pas d'erreur) incrémenter l'index *)
set i to i + 1
set laFin to space & "#" & i & suffixe
on error (* s'il n'existe pas (erreur) c'est bon. *)
exit repeat
end try
end repeat
return nom_ & laFin
end creeNomUnique
-- =============
on quelTraducteur(listeTrad, msg_, traducteur_)
tell application ¬
(path to frontmost application as string) to ¬
set monChoix to ¬
choose from list listeTrad with prompt msg_ ¬
default items traducteur_ as list
if monChoix is false then error msg5 number 8005
return (monChoix as text)
end quelTraducteur
-- =============
on enregistreSous(fichier_, traducteur_, chemin_)
if my quelOS() is not less than "1050" then set traducteur_ to my textAsStringData(traducteur_)
tell application "AppleWorks 6"
activate
try
save document 1 in file chemin_ ¬
using translator traducteur_
(* enregistre dans le dossier sur le bureau,
? save in the folder on the desktop *)
on error
set rapport to ¬
rapport & msg94 & fichier_ & return
end try
end tell -- to AppleWorks
repeat 10 times
try
tell application "Finder" to update file chemin_
set existe to true
on error
set existe to false
end try
if existe is true then exit repeat
end repeat
try
chemin_ as alias
on error -- chemin_ is not present
set rapport to ¬
rapport & msg94 & fichier_ & return
end try
tell application "Finder" to get properties of file chemin_
end enregistreSous
-- =============
on creeDossierDeStockage()
(* S'il n'existe pas,
construit un dossier destination sur le bureau
? If does not exist,
create a destination folder on the desktop *)
set cheminDuBureau to (path to desktop)
if Stockage ends with ":" then set Stockage to ¬
(text 1 thru -2 of Stockage) as text
set cheminDeStockage_ to ¬
"" & cheminDuBureau & Stockage & ":"
try
cheminDeStockage_ as alias
on error (* cheminDeStockage n'existe pas, on le crée
? cheminDeStockage is not available, build it *)
tell application "Finder" to ¬
make new folder at cheminDuBureau ¬
with properties {name:Stockage}
end try
return cheminDeStockage_
end creeDossierDeStockage
-- ===========
on exploreTraite(elem, les_infos, ptree)
set elem_ to elem as text
if (folder of les_infos) then
try
set pf to (package folder of les_infos) as boolean
on error
set pf to (package of les_infos) as boolean
end try
if pf is true then (* amandine *)
set rapport to rapport & msg93 & elem_ & return
(* Attention, un package EST un dossier "spécial".
? Caution, a package IS a "special" folder. *)
else
my ExploreUnDossier(elem_, ptree)
end if -- (package?
else
if file creator of les_infos is "BOBO" then
my TraiteUnFichier(elem_, les_infos, ptree)
else
set rapport to rapport & msg93 & elem_ & return
(* Rejette fichier non Claris/AppleWorks.
? Skip non Claris/AppleWorks files. *)
end if -- file type?
end if
end exploreTraite
-- ===========
on ExploreUnDossier(dossier, ptree)
repeat with nomElement in ¬
list folder dossier without invisibles
set cheminElement to dossier & nomElement
tell application "Finder" to ¬
set C to name of (dossier as alias)
my exploreTraite(cheminElement as alias, ¬
(info for file cheminElement), ptree & C & ":")
end repeat
end ExploreUnDossier
-- ===========
on TraiteUnFichier(leFichier, les_infos, ptree)
tell application "Finder" to set ¬
leVraiNom to (name of alias leFichier)
if leVraiNom ends with ".cwk" then ¬
set leVraiNom to ¬
(text 1 thru -5 of leVraiNom) as text
(* élimine l'extension .cwk, laisse l'extension ".cws" des modèles
? strip .cwk extension, keep extension ".cws" of template files *)
set tDoc to file type of les_infos
if tDoc is in {"CWWP", "TEXT", "sWWP"} then
set {leTraducteur, monExtension} to ¬
{traducteurWP, extensionWP}
else if tDoc is in {"CWSS", "sWSS"} then
set {leTraducteur, monExtension} to ¬
{traducteurSS, extensionSS}
else if tDoc is in {"CWDB", "sWDB"} then
set {leTraducteur, monExtension} to ¬
{traducteurDB, extensionDB}
else if tDoc is in {"CWPT", "sWPT", "CWGR", "sWGR"} then
set {leTraducteur, monExtension} to ¬
{traducteurGR, extensionGR}
else
error msg7 number 8007
end if -- tDoc?
if leTraducteur is not NoTranslation then
tell application "AppleWorks 6"
try
open alias leFichier
end try
set nb_Ouverts to (count each document)
end tell -- to AppleWorks
if nb_Ouverts > nbDocsOuverts then
(* Le fichier a pu être ouvert.
? The file is really open. *)
set C to my createDirTree(cheminDeStockage, ptree)
(* ici il faut créer un nom unique *)
set nouvoNom to my creeNomUnique(C, leVraiNom, monExtension)
set nouveauChemin to C & nouvoNom
if leTraducteur is traducteurGR then
set end of listeGraphiques to ¬
{leFichier, leTraducteur, nouveauChemin}
(* on enregistreSousra les graphiques plus tard
? will save graphics later *)
else
my enregistreSous(leFichier, leTraducteur, nouveauChemin)
end if -- leTraducteur is traducteurGR
tell application "AppleWorks 6" to ¬
close document 1 without saving
else
set rapport to ¬
rapport & msg92 & leFichier & return
end if -- nb_Ouverts?
else
set rapport to ¬
rapport & msg91 & leFichier & return
end if -- leTraducteur?
end TraiteUnFichier
-- ===========
on createDirTree(rc, p)
(*
string rc : root container path where to start directory tree
string p : path string such as "aaa:bbb:ccc:"
return string (rc & p) : path to created directory, such as "rc:aaa:bbb:ccc:"
*)
try
(rc & p) as alias
return (rc & p) -- rc & p is already present
on error --
end try
try
set AppleScript's text item delimiters to ":"
set cc to text items of p
set AppleScript's text item delimiters to ""
set cc to items 1 thru -2 of cc
on error
set AppleScript's text item delimiters to ""
return rc
end try
set x to rc
repeat with C in cc
try
set y to x & C & ":"
y as alias -- check its presence
set x to y
on error
tell application "Finder" to ¬
set x to ¬
(make new folder at item x ¬
with properties {name:C}) as text
end try
end repeat
return x
end createDirTree
-- ===========
on quelOS()
set the hexData to system attribute "sysv"
set hexString to {}
repeat 4 times
set hexString to ((hexData mod 16) as string) & hexString
set hexData to hexData div 16
end repeat
return hexString as string
end quelOS
-- =============
(* Merci/Thanks Hiroto *)
on textAsStringData(t)
(*
text t : source text
return data : «data TEXT...», where ... is hexadecimal representation of t as MacRoman string.
*)
set enTexte to do shell script "printf " & quoted form of t & " | iconv -f utf-8 -t macroman | perl -0777 -ne 'print unpack \"H*\", $_;'"
run (run script "
script
return «data TEXT" & enTexte & "»
end script")
end textAsStringData
-- =============
on loadQTTranslators() (* Merci/Thanks Hiroto *)
(*
Une bidouille pour s'affranchir d'un bug d'AW6
Ce dernier "perd" les traducteurs [QT]
après l'ouverture d'un document quelconque.
Cette routine aberrante force AW6 à reconstruire
une liste de traducteurs complète (sans le relancer).
? A workaround of AW6's bug
AW6 will lose QT origin translators in export/import
translators list after opening a document of any kind.
This absurd handler is to make AW6 recall them in the list
(without restarting AW6)
*)
set n to ((time of (current date)) as string) & ".cwk"
set f to (path to desktop as string) & n
tell application "AppleWorks 6"
activate
make new document with properties ¬
{document kind:drawing document, name:n}
tell drawing area of document n to ¬
make new oval at front with properties ¬
{bounds:{50, 50, 200, 100}}
close document n saving in f
end tell
-- cleaning up dummy document
try
tell application "Finder" to delete f as alias
end try
end loadQTTranslators
-- ===========
on construitListeTraducteurs()
tell application "AppleWorks 6"
set traducteurs_ to export translators
if "[QT]" is not in (traducteurs_ as text) then
my loadQTTranslators() (* Merci/Thanks Hiroto *)
set traducteurs_ to export translators
end if
end tell -- to AppleWorks
return traducteurs_
end construitListeTraducteurs
-- =============
on prepareMessages()
if englishMsg is true then
set msg0 to "This script is not compatible" & return & ¬
"with this version of AppleWorks." & return & ¬
"Please use version 6.0" & return & "or higher..."
set msg1 to "Aworks prefs are corrupted."
set msg5 to "Good bye !"
set msg7 to "this document kind is not treated !"
set msg8 to "Unsaved files."
set msg91 to "Not copied"
set msg92 to "Not open"
set msg93 to "Rejected"
set msg94 to "Failed"
set msg95 to "Choose a translator for" & ¬
return & "Word processing"
set msg96 to "Choose a translator for" & ¬
return & "Spreadsheets"
set msg97 to "Choose a translator for" & ¬
return & "Database"
set msg98 to "Choose a translator for" & ¬
return & "graphic docs"
set msg99 to "Oops"
set NoTranslation to " No translation"
set Bttns1 to {"Cancel", "Reset", " OK "}
else
set msg0 to "Ce script n'est pas compatible" & ¬
return & "avec cette version d?AppleWorks." & return & ¬
"Veuillez utiliser une version 6.0" & return & ¬
"ou plus récente..."
set msg1 to "Préférences AppleWorks corrompues."
set msg5 to "Au revoir !"
set msg7 to "Format non géré !"
set msg8 to "Fichiers non enregistrés."
set msg91 to "Pas copié"
set msg92 to "Pas ouvert"
set msg93 to "Refusé"
set msg94 to "Avorté"
set msg95 to "Choisir un traducteur pour" & ¬
return & "Traitement de textes"
set msg96 to "Choisir un traducteur pour" & ¬
return & "Tableurs"
set msg97 to "Choisir un traducteur pour" & ¬
return & "Base de données"
set msg98 to "Choisir un traducteur pour" & ¬
return & "documents Graphiques"
set msg99 to " Vu "
set NoTranslation to " FORMAT ORIGINAL"
set Bttns1 to {"Annuler", "Modifier", "Accepter"}
end if
set msg91 to "### " & msg91 & " ### "
set msg92 to "### " & msg92 & " ### "
set msg93 to "### " & msg93 & " ### "
set msg94 to "### " & msg94 & " ### "
set {traducteurWP, traducteurSS, ¬
traducteurDB, traducteurGR} to ¬
{NoTranslation, NoTranslation, ¬
NoTranslation, NoTranslation}
end prepareMessages
--[/SCRIPT] |
Puisse-t-il servir à d'autres conservateurs d'antiquités !
Noël |
|
| Revenir en haut de page |
|
 |
|
|
Vous ne pouvez pas poster de nouveaux sujets dans ce forum Vous ne pouvez pas répondre aux sujets dans ce forum Vous ne pouvez pas éditer vos messages dans ce forum Vous ne pouvez pas supprimer vos messages dans ce forum Vous ne pouvez pas voter dans les sondages de ce forum
|
|