Appleworks batch convert to PDF

I have a few thousand applework documents that I wish to convert to PDF - is there a solution?

Mac OS X (10.5.5)

Posted on Aug 25, 2009 10:05 AM

Reply
7 replies

Aug 26, 2009 10:20 AM in response to Dominic O'Neill

I'm able to write an AppleScript but there is a problem:

Mac OS X 10.5 is the minimal requirement.
I have it on a machine but it's not at home everydays so, I don't know when I will be able to do the trick.

The idea is to use a script treating a bunch of files.
The print dialog would be used to send the PDF in the predefined default folder.
A folder action script attached to this folder would datetime stamp the received PDF so there will not be problems of duplicates.

I don't wish to post a script if it was not tested before.

Yvan KOENIG (VALLAURIS, France.) mercredi 26 août 2009 19:20:17

Aug 27, 2009 7:56 AM in response to KOENIG Yvan

Done !

--

--[SCRIPT batch_AW2PDF]
(*
This script batch prints AW docs in PDF files.
To use the script, save it as a script or as an "Application Bundle".
As it's not a script which will be used daily, it's not useful to install it in the Scripts Menu.
Run it (or double click its icon)
navigate to the folder containing the docs
click "OK"
or
drag and drop AW documents or folders
containing AW documents on the script's icon.
In both cases they will be saved as PDF documents.
Yvan KOENIG (Vallauris, FRANCE)
2009/08/27
*)
--=====
(* Des globales *)
property storeOnDesktop : true (*
true = dest folder will be on Desktop
false = dest folder will be in "~/Documents"
*)
property msg3 : "" -- globale
property msg90 : "" -- globale
property msg91 : "" -- globale
property msg94 : "" -- globale
property msg97 : "" -- globale
property rapport : "" -- globale
property dossierParDefaut : "" -- globale
property dossierDeStockage : "" -- globale
--=====
on run
tell application "System Events" to set dossier to choose folder (*
dans un bloc System Events pour avoir un titre de dialogue "localisé"
• in a System Events block to get a localized dialog title. *)
my main({dossier})

end run
--=====
on open sel
my main(sel)
end open
--=====
on main(sel)
local elem, elemT, ptree, nomDuRapport, p2d, p2r, MsgErr, NroErr

if (system attribute "sys2") < 5 then
if (do shell script "defaults read 'Apple Global Domain' AppleLocale") starts with "fr_" then
error "Ce script requiert MacOS X 10.5 ou supérieur !" number 8001
else
error "This script requires MacOS X 10.5 or higher !" number 8001
end if
end if

my activateGUIscripting()
my nettoie()
my |prépareMessages|()

set dossierParDefaut to my getDossierParDefaut()
set dossierDeStockage to my creeDossierDeStockage("wasAWnowPDF")
try
repeat with elem in sel
try
set elemT to elem as text
tell application "System Events" to tell disk item (elem as text)
if class is folder then
set ptree to ""
else
set ptree to path of container
end if
end tell -- System Events
my exploreTraite(elem, ptree)
end try
end repeat

if rapport = "" then set rapport to msg90 (*
crée un fichier texte sur le Bureau *)
set nomDuRapport to "report_AW2PDF.txt"
set p2d to path to desktop
set p2r to (p2d as text) & nomDuRapport
tell application "System Events"
if exists (file p2r) then delete (file p2r)
make new file at end of p2d with properties {name:nomDuRapport}
end tell -- System Events

write (rapport as text) to (p2r as alias)

my afficheLeMessage(msg3) (*
Traitement terminé
• Export done.
*)
on error MsgErr number NroErr
if NroErr is not -128 then
beep 2
tell application (path to frontmost application as string) to ¬
display alert "" & NroErr & " : " & MsgErr giving up after 20
end if -- NroErr is…
end try

my nettoie()

end main
--=====
on exploreTraite(elem, ptree) (*
elem est un alias
• elem is an alias *)
local elemT, laClasse, UTI
set elemT to elem as text
tell application "System Events" to tell disk item elemT
set laClasse to class as text
try
set UTI to type identifier
on error
set UTI to ""
end try
end tell -- System Events
if (UTI is not "") and UTI is not "com.apple.appleworks.cwk" then
set rapport to rapport & elemT & msg94 & return (*
Attention, ce n'est pas un document AW.
• Caution, it's not an AW document *)
else if UTI is "com.apple.appleworks.cwk" then
my traiteUnFichier(elemT, UTI)
else if laClasse is in {"file package", "«class cpkg»"} then
set rapport to rapport & elemT & msg91 & return (*
Attention, un package EST un dossier "spécial".
• Caution, a package IS a "special" folder. *)
else if laClasse is in {"folder", "«class cfol»"} then
my ExploreUnDossier(elemT, ptree)
else
set rapport to rapport & elemT & msg94 & return (*
Pas un document AW.
• not an AW file. *)
end if
end exploreTraite
--=====
on ExploreUnDossier(dossier, ptree)
local nomElement, cheminElement
repeat with nomElement in list folder dossier without invisibles
try
set cheminElement to dossier & (nomElement as text)
tell application "System Events" to set c to name of folder dossier
my exploreTraite(cheminElement as alias, ptree & c & ":")
on error errmsg number errNbr
set rapport to rapport & dossier & msg97 & return & errNbr & return & errmsg
end try
end repeat
end ExploreUnDossier
--=====
on afficheLeMessage(m)
beep 1
tell application (path to frontmost application as string)
activate
display alert m giving up after 10
end tell
end afficheLeMessage
--=====
on traiteUnFichier(cheminDocAW, UTI)
local nomSource, nomCourt, nomComplet, cheminPDFtemporaire, cheminPDFfinal

tell application "AppleWorks 6"
activate
open file cheminDocAW
delay 0.5
set docName to name of document 1
set nomCourt to get name of window 1
set nomComplet to nomCourt & ".pdf"
set cheminPDFtemporaire to dossierParDefaut & nomComplet
tell application "System Events"
if exists (file cheminPDFtemporaire) then set name of file cheminPDFtemporaire to nomCourt & my horoDateur(modification date of file cheminPDFtemporaire) & ".PDF" (* name stamped *)
end tell -- System Events

tell application "System Events" to tell process "AppleWorks 6"
--tell menu bar 1 to tell menu bar item 3 to tell menu 1 to click menu item 16 (* trigger the Print menu *)
keystroke "p" using {command down} (* trigger the Print menu *)
click menu button 1 of window 1 (* click button (PDF) *)
click menu item 1 of menu 1 of menu button 1 of window 1 (* click item Print in a PDF file *)
keystroke return (* idem click OK *)
end tell -- System Events…
end tell -- AppleWorks

my wait4File(cheminPDFtemporaire)
-- puis on déplace vers le dossier de stockage
if dossierDeStockage is not dossierParDefaut then (* we must move the file from folder dossierParDefaut to folder dossierDeStockage *)
set cheminPDFfinal to dossierDeStockage & nomComplet
tell application "System Events" to if exists (file cheminPDFfinal) then set name of file cheminPDFfinal to nomCourt & my horoDateur(modification date of file cheminPDFfinal) & ".PDF"
tell application "Finder" to duplicate file cheminPDFtemporaire to folder dossierDeStockage (*
• before 10.5, System Events is unable to move *)
my wait4File(cheminPDFfinal)
tell application "System Events" to if exists file cheminPDFtemporaire then delete file cheminPDFtemporaire
end if -- dossierDeStockage is not…
tell application "AppleWorks 6" to close document docName without saving
end traiteUnFichier
--=====
(* Wait that the file is completely written on disk
*)
on wait4File(p) (*
• p must be Unicode text *)
local oldSize, newSize
set oldSize to 0
repeat
try
tell application "System Events" to set newSize to physical size of file p
if oldSize < newSize then
set oldSize to newSize
else
exit repeat
end if
end try
end repeat
end wait4File
--=====
on getPlistValue(valName, default)
local thePlist, u
set thePlist to (path to preferences folder as Unicode text) & "com.apple.appleworks.plist"
tell application "System Events"
if exists file thePlist then
tell contents of property list file thePlist
try
set u to (value of property list item valName) (* Unicode Text *)
on error (*
On est là si AppleWorks n'a rien enregistré avec des préférences neuves
• Here if AppleWorks never saved with the new preferences file. *)
set u to default
end try
end tell -- to contents of…
else (*
On est là s'il n'y a pas de fichier de préférences
• Here if there is no preferences file. *)
set u to default
end if
end tell -- to system events
return u
end getPlistValue
--=====
on getDossierParDefaut()
local ky, u
set ky to "AppleNavServices:PutFile:1935767141:Path"
set u to my getPlistValue(ky, "~/Desktop")
set u to (POSIX file (do shell script "echo " & u)) as text
if u ends with ":" then
return u
else
return (u & ":")
end if
end getDossierParDefaut
--=====
(* Build a stamp from the modification date_time
*)
on horoDateur(dt)
local annee, mois, jour, lHeure, lesSecondes, lesMinutes
set annee to year of dt
set mois to month of dt as number (* existe depuis 10.4 *)
set jour to day of dt
set lHeure to time of dt
set lesSecondes to (lHeure mod 60)
set lHeure to round (lHeure div 60)
set lesMinutes to (lHeure mod 60)
set lHeure to round (lHeure div 60)

return "_" & annee & text -2 thru -1 of ("00" & mois) & text -2 thru -1 of ("00" & jour) & "-" & text -2 thru -1 of ("00" & lHeure) & text -2 thru -1 of ("00" & lesMinutes) & text -2 thru -1 of ("00" & lesSecondes)
(*
• Here, the stamp is "_YYYYMMDD-hhmmss" *)
end horoDateur
--=====
on creeDossierDeStockage(nom) (*
S'il n'existe pas, construit un dossier destination sur le bureau ou dans "~/Documents"
• If does not exist, create a destination folder on the desktop or in "~/Documents"
*)
local dd, dds
if storeOnDesktop is true then
set dd to path to desktop as Unicode text
else
set dd to path to documents folder as Unicode text
end if

if nom ends with ":" then
set dds to dd & nom
else
set dds to dd & nom & ":"
end if
(*
dossierDeStockage n'existe pas, on le crée
• dossierDeStockage is not available, build it *)
tell application "System Events" to if not (exists item dds) then make new folder at end of folder dd with properties {name:nom}
return dds as Unicode text
end creeDossierDeStockage
--=====
on activateGUIscripting()
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
end tell
end activateGUIscripting
--=====
on nettoie() (*
pour ne pas stocker dans le fichier script
• So it will not be stored in the script file *)
set msg3 to ""
set msg90 to ""
set msg91 to ""
set msg94 to ""
set msg97 to ""
set rapport to ""
set dossierParDefaut to ""
set dossierDeStockage to ""
end nettoie
--=====
on |prépareMessages|()
if (do shell script "defaults read 'Apple Global Domain' AppleLocale") starts with "fr_" then
set msg3 to "Terminé !"
set msg90 to "Conversion réussie sans incident."
set msg91 to " est un Package !"
set msg94 to " n’est pas un fichier AppleWorks !"
set msg97 to " n’a pu être identifié !"
else
set msg3 to "Done !"
set msg90 to "No problem during the recoding process."
set msg91 to " is a Package !"
set msg94 to " is not an AppleWorks file !"
set msg97 to " can’t be identified !"
end if
end |prépareMessages|
--=====
--[/SCRIPT]
--


It's less complex than my first idea.
This single script does all the job.

Yvan KOENIG (VALLAURIS, France) jeudi 27 août 2009 16:56:01

Sep 4, 2009 10:49 AM in response to KOENIG Yvan

I got them.

Snow Leopard introduced changes in the behavior of AppleWorks driven by AppleScript and in the behavior of Print to PDF.

Here is a modified version.

--

--[SCRIPT batch_AW2PDF]
(*
This script batch prints AW docs in PDF files.

To use the script, save it as a script or as an "Application Bundle".
As it's not a script which will be used daily, it's not useful to install it in the Scripts Menu.

Run it (or double click its icon)
navigate to the folder containing the docs
click "OK"

or

drag and drop AW documents or folders
containing AW documents on the script's icon.

In both cases they will be saved as PDF documents.

Yvan KOENIG (Vallauris, FRANCE)
2009/08/27
2009/09/04 -- for 10.6
*)
--=====
(* Des globales *)
property storeOnDesktop : true (*
true = dest folder will be on Desktop
false = dest folder will be in "~/Documents"
*)
property msg3 : "" -- globale
property msg90 : "" -- globale
property msg91 : "" -- globale
property msg94 : "" -- globale
property msg97 : "" -- globale
property rapport : "" -- globale
property dossierParDefaut : "" -- globale
property dossierDeStockage : "" -- globale
--=====
on run
set dossier to choose folder
--tell application "System Events" to set dossier to choose folder
(*
dans un bloc System Events pour avoir un titre de dialogue "localisé"
• in a System Events block to get a localized dialog title. *)
my main({dossier})

end run
--=====
on open sel
my main(sel)
end open
--=====
on main(sel)
local elem, elemT, ptree, nomDuRapport, p2d, p2r, MsgErr, NroErr

if (system attribute "sys2") < 5 then
if (do shell script "defaults read 'Apple Global Domain' AppleLocale") starts with "fr_" then
error "Ce script requiert MacOS X 10.5 ou supérieur !" number 8001
else
error "This script requires MacOS X 10.5 or higher !" number 8001
end if
end if

my activateGUIscripting()
my nettoie()
my |prépareMessages|()

set dossierParDefaut to my getDossierParDefaut()
set dossierDeStockage to my creeDossierDeStockage("wasAWnowPDF")
try
repeat with elem in sel
try
set elemT to elem as text
tell application "System Events" to tell disk item (elem as text)
if class is folder then
set ptree to ""
else
set ptree to path of container
end if
end tell -- System Events
my exploreTraite(elem, ptree)
end try
end repeat

if rapport = "" then set rapport to msg90 (*
crée un fichier texte sur le Bureau *)
set nomDuRapport to "report_AW2PDF.txt"
set p2d to path to desktop
set p2r to (p2d as text) & nomDuRapport
tell application "System Events"
if exists (file p2r) then delete (file p2r)
make new file at end of p2d with properties {name:nomDuRapport}
end tell -- System Events

write (rapport as text) to (p2r as alias)

my afficheLeMessage(msg3) (*
Traitement terminé
• Export done.
*)
on error MsgErr number NroErr
if NroErr is not -128 then
beep 2
tell application (path to frontmost application as string) to ¬
display alert "" & NroErr & " : " & MsgErr giving up after 20
end if -- NroErr is…
end try

my nettoie()

end main
--=====
on exploreTraite(elem, ptree) (*
elem est un alias
• elem is an alias *)
local elemT, laClasse, UTI
set elemT to elem as text
tell application "System Events" to tell disk item elemT
set laClasse to class as text
try
set UTI to type identifier
on error
set UTI to ""
end try
end tell -- System Events
if (UTI is not "") and UTI is not "com.apple.appleworks.cwk" then
set rapport to rapport & elemT & msg94 & return (*
Attention, ce n'est pas un document AW.
• Caution, it's not an AW document *)
else if UTI is "com.apple.appleworks.cwk" then
my traiteUnFichier(elemT, UTI)
else if laClasse is in {"file package", "«class cpkg»"} then
set rapport to rapport & elemT & msg91 & return (*
Attention, un package EST un dossier "spécial".
• Caution, a package IS a "special" folder. *)
else if laClasse is in {"folder", "«class cfol»"} then
my ExploreUnDossier(elemT, ptree)
else
set rapport to rapport & elemT & msg94 & return (*
Pas un document AW.
• not an AW file. *)
end if
end exploreTraite
--=====
on ExploreUnDossier(dossier, ptree)
local nomElement, cheminElement
repeat with nomElement in list folder dossier without invisibles
try
set cheminElement to dossier & (nomElement as text)
tell application "System Events" to set c to name of folder dossier
my exploreTraite(cheminElement as alias, ptree & c & ":")
on error errMsg number errnbr
set rapport to rapport & dossier & msg97 & return & errnbr & return & errMsg
end try
end repeat
end ExploreUnDossier
--=====
on afficheLeMessage(m)
beep 1
tell application (path to frontmost application as string)
activate
display alert m giving up after 10
end tell
end afficheLeMessage
--=====
on traiteUnFichier(cheminDocAW, UTI)
local nomSource, nomCourt, nomComplet, cheminPDFtemporaire, cheminPDFfinal
set theDoc to cheminDocAW as alias
tell application "AppleWorks 6"
activate
open theDoc
delay 0.5
set docName to name of document 1
set nomCourt to get name of window 1
set nomComplet to nomCourt & ".pdf"
set cheminPDFtemporaire to dossierParDefaut & nomComplet
tell application "System Events"
if exists (file cheminPDFtemporaire) then set name of file cheminPDFtemporaire to nomCourt & my horoDateur(modification date of file cheminPDFtemporaire) & ".PDF" (* name stamped *)
end tell -- System Events

tell application "System Events" to tell process "AppleWorks 6"
--tell menu bar 1 to tell menu bar item 3 to tell menu 1 to click menu item 16 (* trigger the Print menu *)
keystroke "p" using {command down} (* trigger the Print menu *)
click menu button 1 of window 1 (* click button (PDF) *)
click menu item 1 of menu 1 of menu button 1 of window 1 (* click item Print in a PDF file *)
keystroke return (* idem click OK *)
end tell -- System Events…
end tell -- AppleWorks
--log "attends temporaire"
my wait4File(cheminPDFtemporaire)
--log "temporaire est prêt" & return & dossierDeStockage & return & dossierParDefaut
-- puis on déplace vers le dossier de stockage
if dossierDeStockage is not dossierParDefaut then (* we must move the file from folder dossierParDefaut to folder dossierDeStockage *)
set cheminPDFfinal to dossierDeStockage & nomComplet
tell application "System Events" to if exists (file cheminPDFfinal) then set name of file cheminPDFfinal to nomCourt & my horoDateur(modification date of file cheminPDFfinal) & ".PDF"
tell application "Finder" to duplicate file cheminPDFtemporaire to folder dossierDeStockage (*
• before 10.5, System Events is unable to move *)
my wait4File(cheminPDFfinal)
--log "final done"
tell application "System Events" to if exists file cheminPDFtemporaire then delete file cheminPDFtemporaire
end if -- dossierDeStockage is not…
tell application "AppleWorks 6"
--log "close document : " & docName
close document docName without saving
end tell
end traiteUnFichier
--=====
(* Wait that the file is completely written on disk
*)
on wait4File(p) (*
• p must be Unicode text *)
local oldSize, newSize
--log "wait4file : " & p
delay 0.5
set oldSize to 0
repeat
try
tell application "System Events"
set newSize to (get physical size of file p)
end tell
if oldSize < newSize then
set oldSize to newSize
else
exit repeat
end if
end try
end repeat

end wait4File
--=====
on getPlistValue(valName, default)
local thePlist, u
set thePlist to (path to preferences folder as Unicode text) & "com.apple.appleworks.plist"
tell application "System Events"
if exists file thePlist then
tell contents of property list file thePlist
try
set u to (value of property list item valName) (* Unicode Text *)
on error (*
On est là si AppleWorks n'a rien enregistré avec des préférences neuves
• Here if AppleWorks never saved with the new preferences file. *)
set u to default
end try
end tell -- to contents of…
else (*
On est là s'il n'y a pas de fichier de préférences
• Here if there is no preferences file. *)
set u to default
end if
end tell -- to system events
return u
end getPlistValue
--=====
on getDossierParDefaut()
local ky, u
if (system attribute "sys2") < 6 then
try
set ky to "AppleNavServices:PutFile:1935767141:Path"
set u to my getPlistValue(ky, "~/Desktop")
set u to (POSIX file (do shell script "echo " & u)) as text
if u ends with ":" then
return u
else
return (u & ":")
end if
on error

return (path to desktop as text)
end try
else
return (path to desktop as text)
end if
end getDossierParDefaut
--=====
(* Build a stamp from the modification date_time
*)
on horoDateur(dt)
local annee, mois, jour, lHeure, lesSecondes, lesMinutes
set annee to year of dt
set mois to month of dt as number (* existe depuis 10.4 *)
set jour to day of dt
set lHeure to time of dt
set lesSecondes to (lHeure mod 60)
set lHeure to round (lHeure div 60)
set lesMinutes to (lHeure mod 60)
set lHeure to round (lHeure div 60)

return "_" & annee & text -2 thru -1 of ("00" & mois) & text -2 thru -1 of ("00" & jour) & "-" & text -2 thru -1 of ("00" & lHeure) & text -2 thru -1 of ("00" & lesMinutes) & text -2 thru -1 of ("00" & lesSecondes)
(*
• Here, the stamp is "_YYYYMMDD-hhmmss" *)
end horoDateur
--=====
on creeDossierDeStockage(nom) (*
S'il n'existe pas, construit un dossier destination sur le bureau ou dans "~/Documents"
• If does not exist, create a destination folder on the desktop or in "~/Documents"
*)
local dd, dds
if storeOnDesktop is true then
set dd to path to desktop as Unicode text
else
set dd to path to documents folder as Unicode text
end if

if nom ends with ":" then
set dds to dd & nom
else
set dds to dd & nom & ":"
end if
(*
dossierDeStockage n'existe pas, on le crée
• dossierDeStockage is not available, build it *)
tell application "System Events" to if not (exists item dds) then make new folder at end of folder dd with properties {name:nom}
return dds as Unicode text
end creeDossierDeStockage
--=====
on activateGUIscripting()
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
end tell
end activateGUIscripting
--=====
on nettoie() (*
pour ne pas stocker dans le fichier script
• So it will not be stored in the script file *)
set msg3 to ""
set msg90 to ""
set msg91 to ""
set msg94 to ""
set msg97 to ""
set rapport to ""
set dossierParDefaut to ""
set dossierDeStockage to ""
end nettoie
--=====
on |prépareMessages|()
if (do shell script "defaults read 'Apple Global Domain' AppleLocale") starts with "fr_" then
set msg3 to "Terminé !"
set msg90 to "Conversion réussie sans incident."
set msg91 to " est un Package !"
set msg94 to " n’est pas un fichier AppleWorks !"
set msg97 to " n’a pu être identifié !"
else
set msg3 to "Done !"
set msg90 to "No problem during the recoding process."
set msg91 to " is a Package !"
set msg94 to " is not an AppleWorks file !"
set msg97 to " can’t be identified !"
end if
end |prépareMessages|
--=====
--[/SCRIPT]
--


Yvan KOENIG (VALLAURIS, France) vendredi 4 septembre 2009 19:49:15

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Appleworks batch convert to PDF

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.