Skript für Konvertierung von .doc/.docx zu .pdf

Liebe Anwender,

ist es möglich per Script ein Word-Dokument (befindet sich in DTPO) in ein PDF-Dokument (dieses sollte in der Gruppe des Word-Dokuments landen) zu konvertieren? Dazu kann auch Word benutzt werden, wie in der folgenden Lösung für den Finder:


property theList : {"doc", "docx"}
on run {input, parameters}
	set output to {}
	tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path
	repeat with x in input
		try
			set theDoc to contents of x
			tell application "Finder"
				set theFilePath to container of theDoc as text
				
				set ext to name extension of theDoc
				if ext is in theList then
					set theName to name of theDoc
					copy length of theName to l
					copy length of ext to exl
					
					set n to l - exl - 1
					copy characters 1 through n of theName as string to theFilename
					
					set theFilename to theFilename & ".pdf"
					
					tell application "Microsoft Word"
						set default file path file path type documents path path theFilePath
						open theDoc
						set theActiveDoc to the active document
						save as theActiveDoc file format format PDF file name theFilename
						copy (POSIX path of (theFilePath & theFilename as string)) to end of output
						close theActiveDoc
					end tell
				end if
			end tell
		end try
	end repeat
	tell application "Microsoft Word" to set default file path file path type documents path path theOldDefaultPath
	return output
end run

Vielen Dank für eure Mühe!

Das folgende, leicht abgewandelte Skript sollte entsprechend funktionieren:


property extensionList : {"doc", "docx"}

tell application id "DNtp"
	set theInput to {}
	set theSelection to the selection
	repeat with theRecord in theSelection
		set theFile to (path of theRecord) as POSIX file
		set theDoc to theFile as alias
		
		tell application "Finder"
			set theFilePath to container of theDoc as text
			set ext to name extension of theDoc
			if ext is in extensionList then
				set theName to name of theDoc
				set theFilename to characters 1 through ((length of theName) - (length of ext) - 1) of theName as string
				set theFilename to theFilename & ".pdf"
				
				tell application "Microsoft Word"
					set theOldDefaultPath to get default file path file path type documents path
					set default file path file path type documents path path theFilePath
					open theDoc
					set theActiveDoc to the active document
					set theFilePath to (path to desktop folder) as string
					set default file path file path type documents path path theFilePath
					save as theActiveDoc file format format PDF file name theFilename
					close theActiveDoc
					set default file path file path type documents path path theOldDefaultPath
				end tell
				
				set theConvertedPath to (theFilePath & theFilename as string)
			end if
		end tell
		
		set theConvertedRecord to import POSIX path of theConvertedPath to (parent 1 of theRecord)
		if exists theConvertedRecord then tell application "Finder" to delete theConvertedPath
	end repeat
end tell

Funktioniert perfekt! Vielen Dank für die Hilfe!