Script file copy overwrite existing working intermittently

Hi all,

Can any one help with my script below please?
Everything works as expected except the “with replacing” line. Sometimes it does it, sometimes it doesn’t which is really weird as I can’t replicate when it does or doesn’t do it. If I remove that line it prompts for the file to replace as you would expect - I don’t want the prompt to appear and just replace the existing.

Additionally the code:

tell application “MakeZipAndMove”
activate
open theDroppedItems
end tell

calls an Automator App that creates a zip archive of theDroppedItems folder and copies it to a specific location on my system. I’ve tried to incorporate these actions into the Applescript so it’s all self contained to no avail so, although not the priority, any help with this too would be greatly appreciated.


on open theDroppedItems – drop the sub Artwork folder
tell application “Finder”
set theAi to first item of ((files of (item 1 of theDroppedItems) whose name extension is “ai”) as alias list)
end tell – finds the Illustrator file within the sub Artwork folder

tell application "Adobe Illustrator"
	activate
	open theAi -- opens the Illustrator file from the sub Artwork folder
	
	tell document 1
		do script "RELEASES UPDATE" from "Dave's" -- runs the specific Illustrator action
	end tell
	
	tell application "Finder"
		set f to ":Users:g-uk-tam1-retail-2:Desktop:PDF's:Not Distilled:" as alias
		move files of entire contents of f to theDroppedItems with replacing
	end tell
	
	
end tell

tell application "MakeZipAndMove"
	activate
	open theDroppedItems
end tell

end open


Many thanks in advance

As far as I know,
set f to “:Users:g-uk-tam1-retail-2:Desktop:PDF’s:Not Distilled:” as alias
is not a valid HFS pathname.

You must insert the name of the volume at its very beginning, something like :
set f to “Macintosh HD:Users:g-uk-tam1-retail-2:Desktop:PDF’s:Not Distilled:” as alias

In fact I would edit more:

tell application "Finder"
	set f to "Macintosh HD:Users:g-uk-tam1-retail-2:Desktop:PDF's:Not Distilled:" as alias
	move (entire contents of f as alias list) to theDroppedItems with replacing
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 14 décembre 2020 15:41:42

As I understand it, your action is distilling the file. This is an asynchronous action, and it takes some time to distill the file. Your Finder is moving the folder without checking if the process of distillation of its ai- file is over.

The solution to the problem is:
You need to save the result of distillation to a different file, not the original one. Then the Finder should check if the new file exists (which means that the distillation is complete). Then you can move the distilled result with Finder. This is the only way to make your script stable.

Checking new file existing is simple. Like this:


tell application "Finder"
repeat until POSIX file output_path exists
        delay 0.1
   end repeat
end tell

or, without Finder:


repeat
	try
		alias output_HFSpath -- distilled file exists?
		exit repeat
	end try
	delay 0.5
end repeat

Not to disagree because Yvan’s point is a valid one, but just a point of information, I ran the following in Script Editor and received the results shown:

set f to ":Users:Robert:Documents:" as alias --> alias "Macintosh HD:Users:Robert:Documents:"

This is explained in the ASLG:

https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_fundamentals.html#//apple_ref/doc/uid/TP40000983-CH218-DontLinkElementID_372

Thanks Ivan - works as expected at every instance.

Sorry KniazidisR, can’t seem to quote your reply… in answer to your post:

The folder “Not Distilled” is kind’ve a red herring - the file doesn’t go through any actions and is just stored in that named folder.

But you have raised an interesting point. When the script activates Illustrator and calls the specific Action there is some “manual” processing going on within Illustrator BEFORE the script should continue on its route. I think I have been lucky in doing the manual processes quickly thus allowing the script to continue correctly, but have purposely delayed my manual process to see what happens - and it’s an issue. So this “checking for file before continuing” is very relevant.
I will look to incorporating this in the script.

Thank you!

To augment Yvan’s reply, if the Desktop concerned is that of the current user, the alias to the folder can be “soft coded” in either of these ways:

tell application "Finder"
	set f to (folder "PDF's:Not Distilled:" of desktop) as alias
	move (entire contents of f as alias list) to theDroppedItems with replacing
end tell
set f to ((path to desktop as text) & "PDF's:Not Distilled:") as alias
tell application "Finder"
	move (entire contents of f as alias list) to theDroppedItems with replacing
end tell

The latter’s slightly quicker at obtaining the alias, but this won’t be noticeable in the context of the script as a whole.

Another point which may have relevance to the original problem is that theDroppedItems is a list of alias(es), not a folder reference….