AI into PDF: works when file is specified, not if variables are used

Hi,

So, I’m fairly new to AppleScript and this is my first big project… I’m trying to write a droplet that will convert AI files into PDF (no, we don’t have acrobat pro on every computer where I work, so yes, this is stupid and could be solved by software, but alas, it won’t be).

I’ve got the script to work IF i specify the exact location of the file and the exact location where I want it to save. When I convert it to a droplet, where I use variables for paths, I get the “can not make some data into expected type” error and I’ve broken down all the pieces and they seem to work just fine. So, if anyone could help me figure out where this is messing up, I’d really appreciate it.

the version that works:

tell application "Adobe Illustrator"
	set destFolder to "Macintosh HD:Users:Katie:Desktop:pdfs:" as string
	set fileName to "threeve"
	set newFilePath to destFolder & fileName & ".pdf"
	
	open file "Macintosh HD:Users:Katie:Desktop:stupid.ai"
	save current document in file newFilePath as pdf ¬
		with options {class:PDF save options ¬
		, compatibility:Acrobat 5 ¬
		, preserve editability:false}
	close current document saving no
	
end tell

version that doesn’t work:


on run
	display dialog "To use this application, drag files onto the icon."
end run

on open dropThis
	tell application "Finder"
		set theItemPath to dropThis as string
		set newPath to characters 1 thru -(3 + 1) of theItemPath as string
		set FinalPath to newPath & ".pdf"
		
	end tell
	
	tell application "Adobe Illustrator"
		open file dropThis
		save current document in file FinalPath as pdf ¬
			with options {class:PDF save options ¬
			, compatibility:Acrobat 5 ¬
			, preserve editability:false}
		close current document saving no
		
	end tell
end open

(I’ve also done the second version using only Illustrator and not Finder to set the variables, either way I get the same error. However, when I test the variables, they come out correct.)

I think I’ll also need to add a repeat to be able to use the droplet for multiple files at a time…

Hi,

the parameter of the on open handler is a list of the dropped files.
Try this, unfortunately the script doesn’t compile (with an error in the save line) on my machine with Illustrator CS3


on run
	display dialog "To use this application, drag files onto the icon."
end run

on open dropThese
	repeat with oneFile in dropThese
		set FinalPath to text 1 thru -4 of name of (info for oneFile) & ".pdf"
		tell application "Adobe Illustrator"
			open oneFile
			save current document in file FinalPath as pdf with options {class:PDF save options , compatibility:Acrobat 5 , preserve editability:false}
			close current document saving no
		end tell
	end repeat
end open

I had to add in the path to the Desktop or it would run, but I wouldn’t get the pdf, but thank you!

Anyone is welcome to use it, if you need it, obviously you’d have to replace the path to the Desktop to work on yours, but it works.

final:

on run
	display dialog "To use this application, drag files onto the icon."
end run

on open dropThese
	repeat with oneFile in dropThese
		set FinalPath to "Macintosh HD:Users:Katie:Desktop:" & text 1 thru -4 of name of (info for oneFile) & ".pdf"
		tell application "Adobe Illustrator"
			open oneFile
			save current document in file FinalPath as pdf with options {class:PDF save options, compatibility:Acrobat 5, preserve editability:false}
			close current document saving no
		end tell
	end repeat
end open

this is a machine independent version


.
set FinalPath to ((path to desktop as text) & text 1 thru -4 of name of (info for oneFile) & ".pdf")
.

Edit:

.or a version, which saves the PDF in the same directory as the original file


.
repeat with oneFile in dropThese
	tell application "Finder" to set parentFolder to container of oneFile as text
	set FinalPath to parentFolder & text 1 thru -4 of name of (info for oneFile) & ".pdf"
.

time sure flies,

nevertheless, for the record:

“can not make some data into expected type” error while saving occurs in connection to the file path type.
(POSIX or not POSIX, this is the question)

Like this it will work:

set MyFilePath to POSIX path of "Mac HD:MyFolder:" & "MyFilename" as string

export current document to POSIX file MyFilePath as JPEG ¬
	with options {class:JPEG export options, artboard clipping:true, quality:80}

or alternatively:

      save current document to POSIX file MyFilePath as pdf ¬
                with options {class:PDF save options, compatibility:Acrobat 5, preserve editability:false}

WiLi