Make drag and drop applescript - PDF Conversion

Hello,

Im working with a PDF to TIFF workflow that I found here: http://macscripter.net/viewtopic.php?id=19319
What I have (pasted below) throws an error where it states: Cant get name of {alias"path:to:file.pdf"}

If I stick to the original script it works fine, but rather then drag and drop, it prompts the user to select a pdf file like so:

set pdfFile to (choose file of type "PDF ")

What am I running up against?
Many thanks for your help.

on open pdfFile
	
	-- Apply the workflow application to the chosen PDF file.
	tell application "PDF to TIFF" to open pdfFile
	
	-- Hang around until the workflow's done its stuff.
	tell application "System Events"
		repeat while (application process "PDF to TIFF" exists)
			delay 0.2
		end repeat
	end tell
	
	tell application "Finder"
		-- Get a sorted list of the sequentially named TIFFs in the folder created by the workflow.
		set conversionsFolder to folder "PDF to TIFF Conversions" of desktop
		set tiffList to (sort (get files of conversionsFolder) by name)
		-- Rename the TIFFs with the original PDF name followed by two digits and ".tiff".
		-- The workflow's numbering system continues to increment over successive runs,
		-- so we need to use our own counter for the digits. Starting at it 100 rather than at 0
		-- ensures that the tens digit exists in the numbers as text. We'll drop the leading "1"s.
		set baseName to (name of pdfFile) & "."
		set counter to 100
		repeat with thisTiff in tiffList
			set counter to counter + 1
			set thisTiff's name to baseName & text 2 thru -1 of (counter as Unicode text) & ".tiff"
		end repeat
		-- Move the renamed TIFFs to the same folder as the PDF file and zap the temporary folder.
		move files of conversionsFolder to container of pdfFile
		delete conversionsFolder
	end tell
	
	beep 2 -- "Finished!"
end open

Hi,

the argument of the on open handler is always a a list of alias specifiers,
you need a repeat loop to process all files


on open pdfFiles
	repeat with aFile in pdfFiles
		-- Apply the workflow application to the chosen PDF file.
		tell application "PDF to TIFF" to open aFile
		.

		.
	end repeat
	beep 2 -- "Finished!"
end open

Instead of “beep 2”, you could also use:

do shell script "afplay \"/System/Library/Components/CoreAudio.component/Contents/Resources/SystemSounds/finder/burn complete.aif\""

it seems as if the repeat isn’t the only thing that needs to change - any chance someone can glance at this? Im getting the following error:



on open pdfFile
	repeat with aFile in pdfFile
		-- Apply the workflow application to the chosen PDF file.
		tell application "PDF to TIFFintel2" to open aFile
		
		-- Hang around until the workflow's done its stuff.
		tell application "System Events"
			tell application "System Events" to activate
			repeat while (application process "PDF to TIFFintel2" exists)
				delay 0.2
			end repeat
			
		end tell
		
		tell application "Finder"
			-- Get a sorted list of the sequentially named TIFFs in the folder created by the workflow.
			set conversionsFolder to folder "PDF to TIFF Conversions" of desktop
			set tiffList to (sort (get files of conversionsFolder) by name)
			-- Rename the TIFFs with the original PDF name followed by two digits and ".tiff".
			-- The workflow's numbering system continues to increment over successive runs,
			-- so we need to use our own counter for the digits. Starting at it 100 rather than at 0
			-- ensures that the tens digit exists in the numbers as text. We'll drop the leading "1"s.
			set baseName to (name of aFile) & "."
			set counter to 100
			repeat with thisTiff in tiffList
				set counter to counter + 1
				set thisTiff's name to baseName & text 2 thru -1 of (counter as Unicode text) & ".tiff"
			end repeat
			-- Move the renamed TIFFs to the same folder as the PDF file and zap the temporary folder.
			move files of conversionsFolder to container of pdfFile
			delete conversionsFolder
		end tell
	end repeat
	beep 2 -- "Finished!"
end open

many thanks

I consciously used the plural pdfFiles in my snippet, to get a “variable not defined” error
if there are other occurrences of pdfFile in the script.
You have to change the line


.
 move files of conversionsFolder to container of pdfFile
.

to


.
 move files of conversionsFolder to container of aFile
.

Note for OS X 10.5, replace “/finder/” with “/system/”.

late reply I know - but I just wanted to thank everyone who helped.

In the end I found that the script was unstable with larger files - and verrryy slow. A lot of what I am trying to convert are PDF’s made from student books laid out with InDesign - often with very large graphics (InDesign will not create TIFFS natively). Regardless of how I managed it - sometimes the script would take 30min to crunch the PDF only to produce an empty directory. I’d see the hard drive space decrease as it went but the files would never materialise. In the end I convinced IT to give me a copy of acrobat pro which does the job nicely. At some point I’ll try to script Acrobat, some day.

Many thanks again.

FYI

You could probably achieve what you wanted with ‘sips’

on open pdfFile
	repeat with aFile in pdfFile
		set tPath to POSIX path of aFile
		set saveTID to AppleScript's text item delimiters
		set AppleScript's text item delimiters to {"/"}
		set theName to text item -1 of tPath
		set AppleScript's text item delimiters to {"."}
		set bareName to text 1 thru text item -2 of theName
		set AppleScript's text item delimiters to saveTID
		do shell script "sips -s format tiff " & tPath & " --out ~/Desktop/" & bareName & ".tiff"
	end repeat
end open

This will take your dropped pdfs (any image file in fact (apart from eps’s)) and save them to your desktop as tiff files.

If you have a lot of files to convert it may well be worth creating a new folder on your Desktop called ‘tiffs’ (or whatever you wanted!) and then changing the ‘shell script’ line to:

do shell script "sips -s format tiff " & tPath & " --out ~/Desktop/tiffs/" & bareName & ".tiff"

Note: The output path now contains /Desktop/tiffs, so if you named your new file something other than ‘tiffs’, change this to reflect the name of your newly created folder on your desktop!

hi,

you may try “ghostscript”.

download it from http://pages.uoregon.edu/koch/ which is version 9.05 (I’ve tested with version 9.02)

Save as Programm:

property destPath : (path to desktop as text) & "GS_PDF2Tiff:"

on open droppedFiles
	do shell script "mkdir -p " & quoted form of POSIX path of destPath
	repeat with i from 1 to count of droppedFiles
		set myFile to item i of droppedFiles
		set myCheckList to my getInfo(myFile)
		
		if item 2 of myCheckList is equal to "Adobe PDF document" then
			---comment: sDEVICE=tiff32nc will result in 32 Cmyk tif  -> -sDEVICE=tiff24nc will result in 24 bit rgb tif
			do shell script "usr/local/bin/gs -q -dNOPAUSE -r300x300 -sDEVICE=tiff24nc -dBATCH -sOutputFile=" & quoted form of POSIX path of (destPath & item 1 of myCheckList) & space & quoted form of POSIX path of myFile
		end if
	end repeat
	beep 2
end open

on getInfo(myAlias)
	tell application "System Events"
		set {myKind, myName, myExtension} to {kind, name, name extension} of disk item (myAlias as text)
		if myExtension is not "" then
			set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, myExtension}
			set myName to text 1 thru -2 of (text item 1 of myName)
		end if
		set tifName to myName & ".tif"
	end tell
	
	return {tifName, myKind}
	
	set AppleScript's text item delimiters to tid
	
end getInfo

I hope it’ll work :slight_smile: