Modification d'un script (convert to pdf.scpt)

Makhno

Membre actif
11 Novembre 2007
568
46
38
Naoned
Salut à vous !

Certains ont peu être déjà vu mes précédents post à un autre endroit du forum. Je voulais transformer des .doc en pdf. On a donc fini par trouver ce script "convert to pdf" (dans /library/scripts/printing scripts). Il y a cependant un petit soucis : le script ne prend pas en compte les fichiers .doc. Je le colle ici, vous allez comprendre :

property RadarProblem3258323IsFixed : false
property type_list : {"JPEG", "GIFf", "PICT", "TIFF", "PDF", "TEXT"}
property extension_list : {"jpg", "gif", "pct", "tif", "pdf", "rtf"}
--html is not currently handled

on run {}
tell application "Finder"
try
set FinderSelection to the selection as alias list
on error
--Finder Scripting fails with one item (Radar problem 2741967)
set FinderSelection to the selection
end try
end tell

if RadarProblem3258323IsFixed then
set FS to FinderSelection
--Ideally, this list could be passed to the open handler
else
set FS to {}
repeat with EachItem in FinderSelection
copy EachItem as alias to end of FS
end repeat
end if

set SelectionCount to number of FS -- count
if SelectionCount is 0 then
set FS to userPicksFolder()
else if the SelectionCount is 1 then
set MyPath to path to me
if MyPath is item 1 of FS then
--If I'm a droplet then I was double-clicked
set FS to userPicksFolder()
end if
else
--I'm not a double-clicked droplet
end if
open FS
end run

on userPicksFolder()
set these_items to {}
set these_items to (choose file with prompt "Select a file to convert to PDF:" of type {"JPEG", "GIFf", "PICT", "TIFF", "TEXT", "RTF"}) as list
end userPicksFolder

on open these_items
set thesefiles to {}
set the item_info to {}
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
set the item_info to info for this_item

if folder of the item_info is true then --if the item is a folder
processFolder(this_item)
else if ((folder of the item_info is false) and ¬
(alias of the item_info is false)) and ¬
(the file type of the item_info is in the type_list) or ¬
((the name extension of the item_info) is in the extension_list) then

set theFilePath to (item i of these_items as string)
set thePOSIXFilePath to POSIX path of theFilePath as string
processFile(thePOSIXFilePath)
end if
end repeat
end open

--process folders
on processFolder(theFolder)
set these_items to list folder theFolder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((theFolder as text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
processFolder(this_item)
else if (alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
set theFilePath to (this_item as string)
set thePOSIXFilePath to POSIX path of theFilePath as string
processFile(thePOSIXFilePath)
end if
end repeat
end processFolder

on processFile(thePOSIXFileName)
try
set terminalCommand to ""
set convertCommand to "/System/Library/Printers/Libraries/./convert "
set newFileName to thePOSIXFileName & ".pdf"
set terminalCommand to convertCommand & "-f " & "\"" & thePOSIXFileName & "\"" & " -o " & "\"" & newFileName & "\"" & " -j \"application/pdf\""

do shell script terminalCommand
end try
end processFile

Finalement, mon problème serait réglé si le script ne prenait plus en compte l'extension et ne se souciait que de l'extension. Voire de rien du tout.
Mais... :D si je peux à peu près comprendre le script, je ne sais pas l'écrire...

Pouvez vous me filer un petit coup de main s'il vous plait? :zen::zen:

Merci ! :up:
 
Je te remercie...
Pourtant l'imprimante pdf marche pour les .doc... c'est juste ce script qui ne veux pas le prendre en compte... C'est pas drôle... :(
 
pour les .doc, essaie de faire un script qui ouvre Word et lance l'impression sous forme pdf peut-être
 
Salut !

Ça pourrait être une chouette mais j'ai la bonne idée de ne pas utiliser Word mais NéoOffice et je ne connait rien aux scripts... Donc...
 
Salut !

Ça pourrait être une chouette mais j'ai la bonne idée de ne pas utiliser Word mais NéoOffice et je ne connait rien aux scripts... Donc...

et par TextEdit (qui a la bonne idée de savoir ouvrir les documents .doc) ?

Je n'ai pas vérifier, mais je pense qu'il est AppleScriptable
 
Bon, ben ca marche moyen...

Je pensait passer par quelque chose comme :
tell application "TextEdit"
print file filename as POSIX file with properties {target printer:"PDF"}
end tell

Mais impossible de trouver le nom d'une target printer pour du PDF.

Mais, fin Janvier 2008 sur la liste Apple, je peut lire :

Il suffit d'installer l'application gratuite "CUPS-PDF"

http://www.macupdate.com/info.php/id/20219

puis de l'"attaquer" en apple script.

-- AppleScript
tell application "Printer Setup Utility"
set current printer to printer "CUPS-PDF"
end tell
tell application "Pages"
tell document 1
print
end tell
end tell
-- end of AppleScript

Ce qui donnerait :
tell application "Printer Setup Utility"
set current printer to printer "CUPS-PDF"
end tell
tell application "TextEdit"
print file filename as POSIX file
end tell

Mais je n'ai pas le temps de tester cela...

Cordialement
 
Je vous remercie de vous intéresser à cela...

J'avais déjà installé Cups-PDF. Je viens d'essayer le dernier bout de scipt proposé, text edit s'ouvre bien mais ensuite j'ai le message d'erreur suivant : "la variable filename n'est pas définie". Y aurait-il le moyen de lui dire d'imprimer ce qui est sélectionné?
J'essaye de voir si je peux combiner avec le script précédent (convert to pdf) qui ouvre un boîte de dialogue mais je n'arrive pas à savoir quels morceaux garder...
 
Je vous remercie de vous intéresser à cela...

J'avais déjà installé Cups-PDF. Je viens d'essayer le dernier bout de scipt proposé, text edit s'ouvre bien mais ensuite j'ai le message d'erreur suivant : "la variable filename n'est pas définie". Y aurait-il le moyen de lui dire d'imprimer ce qui est sélectionné?
J'essaye de voir si je peux combiner avec le script précédent (convert to pdf) qui ouvre un boîte de dialogue mais je n'arrive pas à savoir quels morceaux garder...

Il faut remplacer filename par le chemin complet du fichier, comme cela est fait dans le script original que tu as proposé.

Cordialement
 
Euh... je viens d'essayer, j'ai fait glisser un fichier test.doc dans la fenêtre de l'éditeur de script. l'adresse complète apparaît. Je lance le script, il me dit "fin de ligne prévu mais jeton inconnu trouvé"...
j'ai essayé sans l'extension, il me dit que la variable Users n'est pas définie.

edit :
à quel endroit dans le script que j'avais proposé un chemin complet de fichier apparait? C'est ptetre ça que je n'ai pas compris...
 
A la fin : la fonction

on processFile(thePOSIXFileName)

recoit un path complet.
Il suffirait de tester avant le "try" l'extension .doc et de traiter spécifiquement ces fichiers.

Bien sur il faudrait changer
Select a file to convert to PDF:" of type {"JPEG", "GIFf", "PICT", "TIFF", "TEXT", "RTF"}

en
Select a file to convert to PDF:" of type {"JPEG", "GIFf", "PICT", "TIFF", "TEXT", "RTF","DOC"}

Cordialement
 
  • J’aime
Réactions: Makhno
Bon, aller, on laisse tomber. C'est vraiment trop de galère pour pas grand chose. Pis j'ai l'impression d'abuser de vous et votre temps.
J'ai commencé à transformer mes .doc en .rtf, c'est assez rapide (merci les dossiers intelligents!) et je n'aurais plus de galères. Fini le format microsoft de m****.

Je vous remercie de vous être pris la tête là dessus.

EDIT :
Ah, une nouvelle réponse... c'est sympa. je ne connais vraiment pas assez ce langage pour essayer tout cela. Et je n'aime pas réclamer qu'on me fasse tout le boulot... J'apprendrai ce langage cet été, ça me servira
merci encore