Moving Files From Folder

Hello, I have this script, which I’m using as a droplet:


on open thisItem
	set this_folder to (the POSIX path of thisItem)
	set export_folder to "Macintosh HD:Users:j************:Desktop:AUTOMATOR:export"
	set pdf_folder to "Macintosh HD:Users:j**********:Desktop:AUTOMATOR:PDF"
	tell application "Adobe Illustrator" to open thisItem
	tell application "Adobe Illustrator" to save current document in export_folder as pdf with options {class:PDF save options, PDF preset:"Low res proofing"}
	tell application "Adobe Illustrator" to close current document
	tell application "UltraLowPDF" to open
	tell application "Finder" to move every file of folder "Macintosh HD:Users:j*********:Desktop:AUTOMATOR:PDF" to this_folder
end open

This script should do a few things:

  1. It creates a pdf file from an .ai file using adobe illustrator.
  2. It then runs that pdf file through an automator workflow, which then spits out a pdf into a folder on my desktop.
  3. It then moves that pdf file from the desktop, back to the folder of the original .ai file.

Every part of the script works fine except for step 3, it just seems to ignore it entirely. I’ve tried adding a delay.
I’ve tried moving files with the same method, but without any script before it, which seemed to work fine.

Where am I going wrong?

Thanks in advance!

Hi,

you are moving the new file to thisItem (which is not a folder!), but you want to move the new file to the enclosing folder of the item

tell application "Finder" to move every file of folder "Macintosh HD:Users:jamie.hargrave:Desktop:AUTOMATOR:PDF" to container of this_folder

Thanks for the reply. This did seem like it should work, and has probably fixed one part of the problem, but the script still isn’t moving any files.

I’ve tried to isolate the moving part of the code and created another droplet:


on open thisItem
	set this_folder to (the POSIX path of thisItem)
	tell application "Finder" to move every file of folder "Macintosh HD:Users:j*********:Desktop:AUTOMATOR:PDF" to container of this_folder
end open

However, this is just throwing up an error saying that it can’t get the «class ctnr» of the file dropped on it (-1728).

After trying some stuff out, it seems that it’s the Automator application that seems to be a problem. Anything I put after that part of the script seems to be an issue. I’ve tried just putting a simple

after the

tell application "UltraLowPDF" to open

and even this doesn’t run.

on open thisItem
   set this_folder to (the POSIX path of thisItem)
  .
   tell application "Finder" to move every file of folder "Macintosh HD:Users:j*********:Desktop:AUTOMATOR:PDF" to this_folder
end open

Finder is unable to apply upon a POSIX path.

You would get better results with :

on open thisItem
 #  set this_folder to (the POSIX path of thisItem)
  .
   tell application "Finder" to move every file of folder "Macintosh HD:Users:j*********:Desktop:AUTOMATOR:PDF" to container of thisItem
end open

A bit of cleaning would give :

on open thisItem
	set p2d to path to desktop as text
	set export_folder to p2d & "AUTOMATOR:export"
	set pdf_folder to p2d & "AUTOMATOR:PDF"
	tell application "Adobe Illustrator" 
	open thisItem
	save current document in export_folder as pdf with options {class:PDF save options, PDF preset:"Low res proofing"}
	close current document
	end
	tell application "UltraLowPDF" to open
	tell application "Finder" to move every file of folder pdf_folder to container of thisItem
end open

Yvan KOENIG running Sierra 10.12.0 in French (VALLAURIS, France) vendredi 7 octobre 2016 13:59:45

Unfortunately it seems that the

tell application "UltraLowPDF" to open

breaks the script. Anything placed after this Automator application doesn’t run.

However, the script almost does everything I need, so I’ve just added in a line before that bit to open up a finder window in the pdf_folder so that it makes it easy to just manually drag the files across.

Also cleaned up the script as you suggested :slight_smile: thanks a lot for the help!

If nothing ever executes following

tell application "UltraLowPDF" to open

then I’ve got a couple of suggestions for workarounds.

If everything that ever needs to be saved in pdf_folder always gets moved out as soon as it’s saved, then when the script runs, before it does “tell application “UltraLowPDF” to open,” it could save the value of “container of thisItem” to the comments of pdf_folder. Then you can make a separate Folder Action that watches the folder, and any time a new item appears in it, it gets the path to move it to out of the comments, then moves the item.

Another option would be to do something like this:

on open thisItem
	set this_folder to (the POSIX path of thisItem)
	set export_folder to "Macintosh HD:Users:j************:Desktop:AUTOMATOR:export"
	set pdf_folder to "Macintosh HD:Users:j**********:Desktop:AUTOMATOR:PDF"
	tell application "Adobe Illustrator" to open thisItem
	tell application "Adobe Illustrator" to save current document in export_folder as pdf with options {class:PDF save options, PDF preset:"Low res proofing"}
	tell application "Adobe Illustrator" to close current document
	ignoring application responses
		tell application "UltraLowPDF" to open
	end ignoring
	set PDFfolder to "Macintosh HD:Users:j*********:Desktop:AUTOMATOR:PDF"
	tell application "Finder"
		repeat
			if exists the first file of PDFfolder then
				move every file of PDFfolder to this_folder
				exit repeat
			end if
			delay 5
		end repeat
	end tell
end open

The script will ignore whatever happens with “tell application “UltraLowPDF” to open,” so it should proceed. But of course, it won’t be waiting for UltraLowPDF to finish saving it’s file(s) either, so it checks to see if there are any files there every 5 seconds until there are, then moves them.

If UltraLowPDF does sometimes save out multiple files, this won’t always move them all, it will run and then quit as soon as it finds a single file in the output folder. But if you can predict how many files it’s looking for, the repeat loop can run until they’re all there and then exit.

It would also be a good idea to put a limit on the possible iterations of the repeat loop and display an error eventually, rather than letting it loop forever in the event UltraLowPDF fails to save any files.

You also might run into a problem where it tries to move the file while it’s still saving. I’ve countered that with a repeat loop checking the file size to see if it’s changing, and as soon as it holds steady for a few seconds, assume it’s done and then move the file. There’s probably a better way to do that.