Copying a File from the network

I have worked on this before, but something has changed and the script no longer works. It returns an error saying:

Finder got an error: Can’t set folder “Macinosh HD:Users:DAVID:Desktop:” to folder “Macinosh HD:Users:DAVID:Desktop:”


set my_dialog_result to display dialog "Old Template Number?" default answer ""
set OldJobNum to the text returned of my_dialog_result
set my_dialog_result to display dialog "NEW Template Number?" default answer ""
set NewJobNum to the text returned of my_dialog_result

set OldJobTemplate to OldJobNum & ".jlt"
set NewJobTemplate to NewJobNum & ".jlt"
set OldTemplatePath to "Jobs:4colors:template:" & OldJobTemplate
set NewTemplatePath to "Jobs:4colors:template:" & NewJobTemplate


tell application "Finder"
	set theDupe to duplicate file OldTemplatePath to folder "Macinosh HD:Users:DAVID:Desktop:"
	set name of theDupe to NewJobTemplate

end tell

The problem comes when I set theDupe. As I said, this script worked before, but doesn’t now :frowning:
Also… is there a better way to duplicate this file?

thanks
david

Hi,

the Finder has a property desktop as a shortcut to the current desktop

set theDupe to duplicate file OldTemplatePath to desktop

As I dislike the Finder, I started attempting to trigger System Events with :

set destFolder to path to desktop as text

tell application "System Events"
	duplicate disk item OldTemplatePath to folder destFolder with properties {name:NewJobTemplate}
end tell

but I got the error : “Erreur dans System Events : Files can not be copied.” number -1717

Not too surprised because I was never able to get duplicate to work in System Events.

So I looked at do shell script and this time it behaved flawlessly.

set destFolder to path to desktop as text
do shell script "ditto " & quoted form of POSIX path of OldTemplatePath & space & quoted form of POSIX path of (destFolder & NewJobTemplate)

Third attempt : use the library FileManagerLib announced here by Shane Stanley.

use FMLib : script "FileManagerLib"
use scripting additions

# Here put your code building the different descriptors

set destFolder to path to desktop as text
FMLib's copyItem:OldTemplatePath toMake:(destFolder & NewJobTemplate) withReplacing:true

It behaved flawlessly too.

Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) mardi 5 janvier 2016 15:50:32

I used yvan’s middle solution. That works great… thanks :slight_smile: