New version available :
(1) Save the doc as a native one so export to PDF will behave correctly with newly created documents.
(2) the PDF is no longer saved at the root of the HD but in the user's Documents folder.
(3) no longer create two copies to join them. A single one is sufficient.
(4) added a property allowing us to choose de name of the final PDF :
(a) use twice.pdf as the old version did
(b) use a dateStamped name : yyyymmdd_hhmmss.pdf
The choice (a) spare HD space.
The choice (b) give us different files .
(5) cleaned a bit the code.
(6) of course, added the ability to display error message in French 😉
--
--[SCRIPT saveAsPdfAndMergeTwoCopies]
(*
Enregistrer le script en tant que Script : saveAsPdfAndMergeTwoCopies.scpt
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Pages:
Il vous faudra peut-être créer le dossier Pages et peut-être même le dossier Applications.
menu Scripts > Pages > saveAsPdfAndMergeTwoCopies
Le script exporte en PDF le document Pages au premier plan,
il duplique le fichier créé puis assemble ces deux copies.
Enfin, il ouvre le fichier résultant.
--=====
L'aide ** Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".
--=====
Save the script as a Script: saveAsPdfAndMergeTwoCopies.scpt
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Pages:
Maybe you would have to create the folder Pages and even the folder Applications by yourself.
menu Scripts > Numbers > saveAsPdfAndMergeTwoCopies
The script export as PDF the frontmost Pages document,
it duplicates it and merge these two PDFs.
At last, it opens the final file.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
--=====
Yvan KOENIG (VALLAURIS, France)
2010/05/30
2010/05/31 -- Now saves the original document and no longer duplicates the first PDF
*)
--=====
property theApp : "Pages"
property useDateStampedPDF : true
(*
true = save as yyyymmddhhmmss.pdf
false = save as twice.pdf
*)
--=====
on run
if theApp is not in {"Numbers", "Pages"} then
if my parleAnglais() then
error "Accept only “Pages” & “Numbers” !"
else
error "Résevé à “Pages” & “Numbers” !"
end if
end if
try
set aPath to quoted form of "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py"
do shell script "ln -s " & aPath & " joinPDF.py"
end try
set p2d to path to documents folder as text
set pdfName to "pdf@_@fdp.pdf"
set pdfPath to p2d & pdfName
if useDateStampedPDF then
set twice to (do shell script "date +_%Y%m%d-%H%M%S") & ".pdf"
else
set twice to "twice.pdf"
end if -- useDateStampedPDF
set twicePath to p2d & twice
tell application "System Events"
if exists disk item pdfPath then delete disk item pdfPath
make new file at end of folder p2d with properties {name:pdfName}
if not useDateStampedPDF then
if exists disk item twicePath then delete disk item twicePath
make new file at end of folder p2d with properties {name:twice}
end if -- not useDateStampedPDF
end tell
if theApp is "Pages" then
set PDFtype to "SLDocumentTypePDF"
else
set PDFtype to "LSDocumentTypePDF"
end if -- theApp
tell application theApp
try
set nativePath to path of document 1
nativePath as text (* issue an error if the document was never saved before *)
save document 1
on error
(*
we are here if the document was never saved before.
Save it with a date_time name.
*)
set nativeName to (do shell script "date +_%Y%m%d-%H%M%S") & "." & theApp
set nativePath to p2d & nativeName
tell application "System Events" to make new file at end of folder p2d with properties {name:nativeName}
save document 1 in nativePath (* So that the document will be saved in its current state *)
end try
save document 1 as PDFtype in (pdfPath as alias)
end tell -- theApp
tell application "System Events"
repeat until exists disk item (pdfPath)
delay 0.1
end repeat
end tell -- System Events
do shell script "./joinPDF.py -o " & quoted form of POSIX path of twicePath & space & quoted form of POSIX path of pdfPath & space & quoted form of POSIX path of pdfPath
tell application "System Events"
delete disk item pdfPath
open disk item twicePath
end tell -- System Events
end run
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--
Yvan KOENIG (VALLAURIS, France) lundi 31 mai 2010 21:21:18