anyone able to help me batch 100’s of rtfd files including images to export to pdf? Either drag n drop or “Hot folder” use? Any help would be appreciated. Currently on 10.8.5
Thanks
Stadler
anyone able to help me batch 100’s of rtfd files including images to export to pdf? Either drag n drop or “Hot folder” use? Any help would be appreciated. Currently on 10.8.5
Thanks
Stadler
You may try this old script.
--[SCRIPT batch_rtfd2PDF.app]
(*
Save the script as an Application Bundle.
Run it or drag and drop a folder icon on its icon.
It export rtfd documents as PDF ones in a folder "wasRtfd_now_PDF".
This one may be on the desktop or in the "~/Documents" folder
according to the property storeOnDesktop.
Assuming that we start with:
trucmuche.rtfd
it will be exported as:
trucmuche.PDF
If a file with the short name already exists
it may be renamed as:
trucmuche_20080128-221639.PDF
the serial number is a packed version of its modification date/time :
2008/01/28T22:16:39
Yvan KOENIG (VALLAURIS, France)
28 janvier 2008
23 septembre 2008
29 mars 2009
2010/09/01
*)
property storeOnDesktop : false
(* true = dest folder will be on Desktop
false = dest folder will be in "~/Documents"
*)
property theApp : "TextEdit"
property theExt : "rtfd"
script o
property msg1 : "" -- globale
property msg3 : "" -- globale
property msg90 : "" -- globale
property msg91 : "" -- globale
property msg92 : "" -- globale
property msg98 : "" -- globale
property msg99 : "" -- globale
property report : "" -- globale
property destFolder : "" -- globale
end script
--=====
on run (* lignes exécutées si on double clique sur l'icône du script application
¢ lines executed if one double click the application script's icon *)
tell application (path to frontmost application as string) to set aFolder to choose folder
tell application "System Events"
set theSel to (path of every file of aFolder whose name extension is "rtfd")
end tell
open theSel
end run
--=====
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) *)
local num_version, xType, elem, reportName, p2d, p2r, MsgErr, NroErr
--my nettoie()
my buildMessages()
my displayMsg(o's msg1) (*
Éviter de cliquer.
¢ Don't click. *)
set o's destFolder to my createStorageFolder() (* Unicode text *)
try
repeat with elem in sel
set elem to elem as text
try
my scanAndTreat(elem, "")
end try
end repeat
if o's report = "" then set o's report to o's msg90 (*
crée un fichier texte sur le Bureau *)
set reportName to "report_rtfd2pdf.txt"
set p2d to path to desktop
set p2r to (p2d as text) & reportName
tell application "System Events"
if exists (file p2r) then delete (file p2r)
make new file at end of p2d with properties {name:reportName}
end tell -- System Events
write (o's report) to (p2r as alias)
my displayMsg(o's 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 dialog "" & NroErr & " : " & MsgErr with icon 0 buttons {o's msg99} giving up after 20
end if -- NroErr is.
end try
--my nettoie()
end open
--=====
on displayMsg(m)
beep 1
tell application (path to frontmost application as string)
activate
display dialog m buttons {o's msg98} default button 1 giving up after 10
end tell
end displayMsg
--=====
on createStorageFolder() (*
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, destName
if storeOnDesktop is true then
set dd to path to desktop as text
else
set dd to path to documents folder as text
end if
set destName to "wasRtfd_now_PDF"
set dds to dd & destName & ":" # don't forget the ending colon !
tell application "System Events"
if not (exists item dds) then make new folder at end of folder dd with properties {name:destName} (*
destFolder n'existe pas, on le crée
¢ destFolder is not available, build it *)
end tell -- to System Events
return dds
end createStorageFolder
--=====
on scanAndTreat(elem, ptree) (*
elem est un Unicode text
¢ elem is an Unicode text *)
local cl_, typeId_
tell application "System Events" to tell disk item elem
set cl_ to (get its class) as text
--log cl_
try
set nameExt_ to name extension
on error
set nameExt_ to ""
end try
end tell -- System Events
--log nameExt_
if nameExt_ is "rtfd" then
my treatADocument(elem) (*
C'est un fichier Rtfd.
¢ It's a Rtfd document *)
else if cl_ is in {"file package", "«class cpkg»"} then
set o's report to o's report & elem & o's msg91 & return (*
"Package", Attention, un package EST un dossier "spécial".
¢ Caution, a package IS a "special" folder. *)
else if cl_ is in {"folder", "«class cfol»"} then
my scanAfolder(elem, ptree)
else
set o's report to o's report & elem & o's msg92 & return (*
"Pas un document Pages".
¢ "Not a Pages document" *)
end if -- cl_ is .
end scanAndTreat
--=====
on scanAfolder(aFolder, ptree)
local elemName, C
tell application "System Events"
repeat with elemName in (name of disk items of folder aFolder whose visible is true)
--log elemName
set C to name of folder aFolder
my scanAndTreat((aFolder & elemName), ptree & C & ":")
end repeat
end tell
end scanAfolder
--=====
on treatADocument(sourcePath) (*
¢ sourcePath is of class Unicode text *)
local sourceName, sourceFolder, p_xport, msgr, NroErr
# Open the rtfd document
tell application "TextEdit"
set curDoc to open file sourcePath
end tell
# Extract its name and the path of its container
tell application "System Events" to tell disk item sourcePath
set sourceName to name (* Unicode text *)
set sourceFolder to path of container (* Unicode HFS path *)
end tell -- System Events
if sourceName ends with theExt then set sourceName to (text 1 thru -(2 + (length of theExt)) of sourceName)
# Builds the name of the PDF to create
set pdfName to sourceName & ".PDF"
# Builds its path
set p_xport to o's destFolder & pdfName
# If already exists such PDF file, rename it according to its modification name
tell application "System Events" to if exists disk item p_xport then set name of disk item p_xport to sourceName & my buildDateTimeStamp(modification date of disk item p_xport) & ".PDF"
my exportAsPDF(o's destFolder, pdfName)
tell application "TextEdit" to close curDoc
end treatADocument
#=============
# Builds a stamp from the modification date_time
on buildDateTimeStamp(aDate)
tell aDate to return "_" & ((text -4 thru -1 of ((its year) + 10000 as text)) & "-" & (text -2 thru -1 of ((its month) + 100 as text)) & "-" & (text -2 thru -1 of ((its day) + 100 as text))) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
# Here, the stamp is "_YYYYMMDD_hhmmss" *)
end buildDateTimeStamp
--=====
on buildMessages()
if (do shell script "defaults read 'Apple Global Domain' AppleLocale") starts with "fr_" then
set o's msg1 to "Éviter de cliquer durant l'exécution du script" & return & "sauf s'il le demande."
set o's msg3 to "Traitement terminé."
set o's msg90 to "Exportation réussie sans incident."
set msg91 to "est un Package"
set msg92 to "n'est pas un document " & theApp
set o's msg98 to " Vu "
set o's msg99 to " Vu "
else
set o's msg1 to "Don't click when the script is running." & return & "Except, of course, if it ask for."
set o's msg3 to "Export done."
set o's msg90 to "No problem during the export process."
set msg91 to "is a Package"
set msg92 to "is not a " & theApp & "'s document"
set o's msg98 to " OK "
set o's msg99 to "Oops"
end if
set o's msg91 to " ### " & msg91 & " ###"
set o's msg92 to " ### " & msg92 & " ###"
end buildMessages
#=====
on exportAsPDF(folderpath, pdfName)
local posixFolderPath, pdfPath, mt, mi, export2Pdf, oldSize
set posixFolderPath to POSIX path of folderpath
set pdfPath to POSIX path of (folderpath & pdfName)
# No need to check if there is a duplicate, we took care of that before
# Code borrowed from Nigel Garvey (http://macscripter.net/viewtopic.php?id=41654)
tell application "System Events"
tell process "TextEdit"
set frontmost to true
set {mt, mi} to {3, 14} # Fichier > Exporter au format PDF.
tell menu bar 1
-- log (get name of menu bar items) (*Apple, TextEdit, Fichier, Édition, Format, Présentation, Fenêtre, Aide*)
-- log (get name of menu bar item mt) (*Fichier*)
tell menu bar item mt to tell menu 1
-- log (get name of menu items) (*Nouveau, Ouvrir., Ouvrir l'élément récent, missing value, Fermer, Tout fermer, Enregistrer, Enregistrer sous., Dupliquer, Renommer., Déplacer vers., Revenir à , missing value, Exporter au format PDF., missing value, Afficher les propriétés, missing value, Format d'impression., Imprimer.*)
-- log (get name of menu item mi) (*Exporter au format PDF.*)
# I no longer rely upon the menu item index but upon the fact that only one of them contains the word "PDF"
considering case
set export2Pdf to name of first menu item whose name contains "PDF"
end considering
click menu item export2Pdf
end tell # menu bar item mt
end tell # menu bar 1
# Wait for the Export sheet
repeat until exists sheet 1 of window 1
delay 0.02
end repeat
tell sheet 1 of window 1
-- get value of text fields) --> {"Sans titre-copy.pdf", ""}
set value of text field 1 to pdfName
end tell
# Open the pane allowing the setting of destination folder
keystroke "g" using {command down, shift down}
repeat until exists sheet 1 of sheet 1 of window 1
delay 0.02
end repeat
# Set the destination folder
tell sheet 1 of sheet 1 of window 1
set value of text field 1 to posixFolderPath
-- log (get name of buttons) (*Aller, Annuler*)
click button 1
end tell
# Save the PDF
tell sheet 1 of window 1
-- log (get name of buttons) (*Enregistrer, Nouveau dossier, Annuler*)
click button 1
end tell
end tell # process
# Wait until the pdf is completely saved
set oldSize to -1
repeat
delay 0.2
if (size of disk item pdfPath) = oldSize then exit repeat
set oldSize to size of disk item pdfPath
end repeat
end tell # "System Events".
end exportAsPDF
--=====
--[/SCRIPT]
Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) jeudi 4 février 2016 19:15:45
FANTASTIC! Works with one small but not a deal breaker…
On El Capitan, the files open, export properly, but never close. I have to close all via the menu. Is there a way to add “close files” to the script as to not bog down the resources when processing 100’s of files? Thank you so much
I don’t understand.
Here is the events log which was issued under El Capitan 10.11.3 when I tested .
tell current application
path to frontmost application as string
end tell
tell application "Script Editor"
choose folder
end tell
tell application "System Events"
get path of every file of alias "SSD 500:Users:YK:Desktop:sourceFolder:" whose name extension = "rtfd"
end tell
tell current application
do shell script "defaults read 'Apple Global Domain' AppleLocale"
beep 1
path to frontmost application as string
activate
end tell
tell application "Script Editor"
display dialog "Éviter de cliquer durant l'exécution du script
sauf s'il le demande." buttons {" Vu "} default button 1 giving up after 10
end tell
tell current application
path to documents folder as text
end tell
tell application "System Events"
exists item "SSD 500:Users:YK:Documents:wasRtfd_now_PDF:"
get class of disk item "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre-copy.rtfd:"
get name extension of disk item "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre-copy.rtfd:"
end tell
tell application "TextEdit"
open file "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre-copy.rtfd:"
end tell
tell application "System Events"
get name of disk item "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre-copy.rtfd:"
get path of container of disk item "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre-copy.rtfd:"
exists disk item "SSD 500:Users:YK:Documents:wasRtfd_now_PDF:Sans titre-copy.PDF"
get modification date of disk item "SSD 500:Users:YK:Documents:wasRtfd_now_PDF:Sans titre-copy.PDF"
set name of disk item "SSD 500:Users:YK:Documents:wasRtfd_now_PDF:Sans titre-copy.PDF" to "Sans titre-copy_2016-02-04_192012.PDF"
set frontmost of process "TextEdit" to true
get name of menu item 1 of menu 1 of menu bar item 3 of menu bar 1 of process "TextEdit" whose name contains "PDF"
click menu item "Exporter au format PDF." of menu 1 of menu bar item 3 of menu bar 1 of process "TextEdit"
exists sheet 1 of window 1 of process "TextEdit"
set value of text field 1 of sheet 1 of window 1 of process "TextEdit" to "Sans titre-copy.PDF"
keystroke "g" using {command down, shift down}
exists sheet 1 of sheet 1 of window 1 of process "TextEdit"
exists sheet 1 of sheet 1 of window 1 of process "TextEdit"
set value of text field 1 of sheet 1 of sheet 1 of window 1 of process "TextEdit" to "/Users/YK/Documents/wasRtfd_now_PDF/"
click button 1 of sheet 1 of sheet 1 of window 1 of process "TextEdit"
click button 1 of sheet 1 of window 1 of process "TextEdit"
get size of disk item "/Users/YK/Documents/wasRtfd_now_PDF/Sans titre-copy.PDF"
get size of disk item "/Users/YK/Documents/wasRtfd_now_PDF/Sans titre-copy.PDF"
get size of disk item "/Users/YK/Documents/wasRtfd_now_PDF/Sans titre-copy.PDF"
end tell
tell application "TextEdit"
close document "Sans titre-copy.rtfd"
end tell
tell application "System Events"
get class of disk item "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre.rtfd:"
get name extension of disk item "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre.rtfd:"
end tell
tell application "TextEdit"
open file "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre.rtfd:"
end tell
tell application "System Events"
get name of disk item "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre.rtfd:"
get path of container of disk item "SSD 500:Users:YK:Desktop:sourceFolder:Sans titre.rtfd:"
exists disk item "SSD 500:Users:YK:Documents:wasRtfd_now_PDF:Sans titre.PDF"
get modification date of disk item "SSD 500:Users:YK:Documents:wasRtfd_now_PDF:Sans titre.PDF"
set name of disk item "SSD 500:Users:YK:Documents:wasRtfd_now_PDF:Sans titre.PDF" to "Sans titre_2016-02-04_192013.PDF"
set frontmost of process "TextEdit" to true
get name of menu item 1 of menu 1 of menu bar item 3 of menu bar 1 of process "TextEdit" whose name contains "PDF"
click menu item "Exporter au format PDF." of menu 1 of menu bar item 3 of menu bar 1 of process "TextEdit"
exists sheet 1 of window 1 of process "TextEdit"
set value of text field 1 of sheet 1 of window 1 of process "TextEdit" to "Sans titre.PDF"
keystroke "g" using {command down, shift down}
exists sheet 1 of sheet 1 of window 1 of process "TextEdit"
exists sheet 1 of sheet 1 of window 1 of process "TextEdit"
set value of text field 1 of sheet 1 of sheet 1 of window 1 of process "TextEdit" to "/Users/YK/Documents/wasRtfd_now_PDF/"
click button 1 of sheet 1 of sheet 1 of window 1 of process "TextEdit"
click button 1 of sheet 1 of window 1 of process "TextEdit"
get size of disk item "/Users/YK/Documents/wasRtfd_now_PDF/Sans titre.PDF"
get size of disk item "/Users/YK/Documents/wasRtfd_now_PDF/Sans titre.PDF"
get size of disk item "/Users/YK/Documents/wasRtfd_now_PDF/Sans titre.PDF"
end tell
tell application "TextEdit"
close document "Sans titre.rtfd"
end tell
tell current application
path to desktop
end tell
tell application "System Events"
exists file "SSD 500:Users:YK:Desktop:report_rtfd2pdf.txt"
make new file at end of alias "SSD 500:Users:YK:Desktop:" with properties {name:"report_rtfd2pdf.txt"}
end tell
tell current application
write "Exportation réussie sans incident." to alias "SSD 500:Users:YK:Desktop:report_rtfd2pdf.txt"
beep 1
path to frontmost application as string
end tell
tell application "TextEdit"
activate
display dialog "Traitement terminé." buttons {" Vu "} default button 1 giving up after 10
«event ascrgdut»
display dialog "Traitement terminé." buttons {" Vu "} default button 1 giving up after 10
end tell
Résultat :
{button returned:" Vu ", gave up:false}
If TextEdit wasn’t open before since the boot of the system, it remains the empty document created when we open the app.
If the app was already run, every rtfd windows are correctly closed.
I left the “annoying” dialog urging us to don’t click because in your original question you wrote that you are running 10.8.6.
For modern systems I would have replace it by a notification.
Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) vendredi 5 février 2016 11:25:57