Applescript: jpg --> .PDF

Hello everyone,

I aplogize if this question has been asked before, because it seems like it is something that would be, but the search didn’t turn anything up. I am trying to write and applescript inside automator to convert jpg files to .pdf files.

I am new to Applescript and the Mac in general, but I know some VB and python coding. I have not sat down to learn applescript yet, so I am sort of doing this off the cuff from my VB and python knowledge. What I am trying to do with this automator action is sort scanned jpg files, batch convert them to .pdf and then combine them to a single .pdf document. The scanner I am using is rather old so it only scans images one at a time into .jpg files.

My code is rather guesswork, but I tried to base it off of what I saw in the sample script on my Mac and in a different automator action over at autmoator world that used Fink or something instead of the Mac conversion system. Chances are I am missing something huge in the script. It executes without error, but I am not getting my outupt so I am stuck there.

Any help would be great as I am not 100% how the IDs are defined or even passed through automator actions. As of note, before this action in automator I have a “sort finder items by ascending order”. Afterwords I plan to have a combine PDF action.

property type_list : {"JPEG", "GIFf", "PICT", "TIFF", "PDF", "TEXT"}
property extension_list : {"jpg", "gif", "pct", "tif", "pdf", "rtf"}

on run {input, parameters}
	try
		repeat with i from 1 to the count of input
			set theFilePath to (this_item as string)
			set this_item to (item i of input) as alias
			set orgFileName to POSIX path of this_item
			set terminalCommand to ""
			set convertCommand to "/System/Library/Printers/Libraries/./convert"
			set newFileName to orgFileName & ".pdf"
			set terminalCommand to convertCommand & "-f " & "\"" & orgFileName & "\"" & " -o " & "\"" & newFileName & "\"" & " -j \"application/pdf\""
			
			do shell script terminalCommand
			
		end repeat
		return input
		
	end try
end run

Model: Macbook
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

No one at all?

Should I perhaps post this in the Applescript section?

Hi,

I’ve tested this as plain AppleScript but it should alsp work in Automator

property extension_list : {"jpg", "gif", "pct", "tif", "pdf", "rtf"}

on run {input, parameters}
	try
		repeat with i in input
			if name extension of (info for i) is in extension_list then
				set orgFileName to POSIX path of i
				set convertCommand to "/System/Library/Printers/Libraries/convert"
				set newFileName to orgFileName & ".pdf"
				set terminalCommand to convertCommand & " -f " & quoted form of orgFileName & " -o " & quoted form of newFileName & " -j \"application/pdf\""
				do shell script terminalCommand
			end if
		end repeat
		return input
	end try
end run

Could you provide me with some details as to how you are running the script?

As what happened with my script it seems to complie and run without error, but no PDf files appear to actually be created. I tried running the script in Automator, as well as in the applescript utility.

Perhaps if you walk me through how you got it to successfully run, and create the files, I can figure out where I am going wrong in the script.

Hi,

I just commented out a few lines, added a choose file line and ran the script in Script Editor

property extension_list : {"jpg", "gif", "pct", "tif", "pdf", "rtf"}

-- on run {input, parameters}
-- 	try
set input to choose file with multiple selections allowed
repeat with i in input
	if name extension of (info for i) is in extension_list then
		set orgFileName to POSIX path of i
		set convertCommand to "/System/Library/Printers/Libraries/convert"
		set newFileName to orgFileName & ".pdf"
		set terminalCommand to convertCommand & " -f " & quoted form of orgFileName & " -o " & quoted form of newFileName & " -j \"application/pdf\""
		do shell script terminalCommand
	end if
end repeat
-- return input
-- 	end try
-- end run