Le 18/01/2013 à 15:49, Luther Fuller <
email@hidden> a écrit :
On Jan 17, 2013, at 3:22 PM, koenig.yvan wrote:
I found the entire URL of the last PDF created thru Print as PDF in :
Macintosh HD:Users:yvankoenig:Library:Preferences:com.apple.print.custompresets.forprinter.Dell_Laser_Printer_3100cn.plist
in the property :
com.apple.print.preset.settings > com.apple.print.PrintSettings.PMOutputFilename
As you may guess, the file is named according to the printer whose driver was used by the print task.
That is the definitive observation! It's the wrong place to store that info, since Print to PDF does not use a printer. And it's probably bad practice to try to set the users printer to set this info correctly.
NSNavlastRootDirectory apperently does not work as it used to.
As this brehavior was not documented, Apple is free to change the behavior of its system.
I repeat what I wrote some minutes ago.
When you are in the Save As Pdf dialog, issue cmd +D so the file will be saved on the Desktop from which you will be able to move it to the wanted location.
This scheme use standard, documented features.
This way you will not be annoyed if Apple change one more time a non documented behavior.
In some scripts I was forced to insert a test for this kind of reason :
if maybe then (* macOS X 10.4.x
'(value of attributes contains 0)': '(value of attribute "AXDisclosureLevel" is 0)' sometimes works in Tiger, sometimes not.
The only possible instances of 0 amongst the attributes are the disclosure level of a sheet row and the index of the first row, which represents a sheet anyway.
Another possibility is '(value of attribute -1 is 0)', which makes me uneasy. *)
set targetSheetRow to first row where ((value of attributes contains 0) and (value of first static text is la_Feuille))
else (* macOS X 10.5.x or higher *)
set targetSheetRow to first row where ((value of attribute "AXDisclosureLevel" is 0) and ((groups is {}) and (value of first static text is la_Feuille)) or (value of first group's first static text is la_Feuille))
end if -- maybe…
An other example is my handler used to print in a PDF.
on imprimeDansPDF(the_App, nom_pdf)
activate application the_App
tell application "System Events" to tell application process the_App
set nbw to count windows
keystroke "p" using command down
(*
Wait for the availability of the sheet *)
repeat
if exists sheet 1 of window 1 then exit repeat
end repeat
# name of menu buttons of sheet 1 of window 1
--> {"PDF"} but I don't know if it's spelled this way worldwide
set PDFButton to first menu button of sheet 1 of window 1
click PDFButton
# name of menu items of menu 1 of PDFButton
--> {"Ouvrir le PDF dans Aperçu", "Enregistrer au format PDF…", "Enregistrer au format PostScript…", "Faxer le document PDF…", missing value, "@ PDF-BAT.qfilter", "@ PDF-prépresse CMJN.qfilter", "@ PDF-web.qfilter", "@ PDFX3-ISO.qfilter", "Add PDF to iTunes", "Envoyer le document PDF par courrier électronique", "Enregistrer le document PDF dans le dossier de reçus web", missing value, "Modifier le menu…"}
click menu item 2 of menu 1 of PDFButton
if modernVersion then
(*
The Print interface is no longer a window but a sheet *)
repeat
if exists sheet 1 of sheet 1 of window 1 then exit repeat
end repeat
tell sheet 1 of sheet 1 of window 1
if nom_pdf is not "" then set value of text field 1 to nom_pdf
# set the target folder to Desktop
keystroke "d" using {command down}
# name of buttons
--> {"Enregistrer", "Nouveau dossier", "Annuler"}
click button 1 # ditto keystroke return
end tell
else
(*
Wait for the availability of the Print window *)
repeat
if (count windows) > nbw then exit repeat
end repeat
# position of text fields of window 1
--> {position:{875, 190}}
(*
Set the name of the new PDF *)
if nom_pdf is not "" then set value of text field 1 of window 1 to nom_pdf
# set the target folder to Desktop
keystroke "d" using {command down}
# name of buttons of window 1
--> {missing value, missing value, missing value, "Enregistrer", "Nouveau dossier", "Annuler"}
click button -3 of window 1 # ditto keystroke return
end if # modernVersion
end tell
end imprimeDansPDF
In this one, I’m a bit annoyed because I discovered the structure change recently so I don't know which is the parameter to test to rule the switch.
I assume that the change was introduced by Mountain Lion but I'm not sure of that and of course, when I booted under Lion some hours ago, I forgot to check that :-(
I found NSSavePanelLastSaveDirectory, tested it, and found that it only works in File/Save, not in Print/Save as PDF.
In a version of my application from a couple of years ago, I required the user to install CUPS-PDF if they wanted this feature. (Saving an emlx file as a pdf)
It seems that the solution to my problem will be to return to using CUPS-PDF.
(Does anyone remember that System 5 came on a single floppy? Damn progress!)
As far as I remember, we were allowed to execute less tasks and had less tools available at this time.