Basic folder copy.

Hi all.

I’ve been trying to work a folder copy action into a script of mine. No matter what or how I try, it always gives an error.

This (the ‘Desktop’ location below is just an example: the actual destination will be set elsewhere in the script) …

set fontCollection to "Volumes:server:Pictures:ImageAssets:Document Fonts:"
set fontDestination to "~:Desktop"

tell application "Finder"
	duplicate fontCollection to fontDestination
end tell

… gives me this error: ‘Finder got an error: Can’t make “Volumes:server:Pictures:ImageAssets:Document Fonts:” into type item.

If use ‘as alias’ on the variables …

set fontCollection to "Volumes:server:Pictures:ImageAssets:Document Fonts:" as alias
set fontDestination to "~:Desktop" as alias

… I get a ‘File Volumes:server:Pictures:ImageAssets:Document Fonts: wasn’t found.’ error “ despite the folder ‘Document fonts’ definitely existing, and the server/volume it resides on being mounted.

I’ve tried other combinations including ‘Folder’ in the duplicate section, but ALWAYS get an error.

Should I use the terminal instead? If so … how?!

Forget: I can get it to work by prompting users for a source and destination folder “ but I wan’t to specify source and destination using variables.

Help!

Okay … I got this to work:

set fontCollection to alias "server:Pictures:ImageAssets:Document fonts:"
set fontDestination to alias "KatMac:Users:Me:Desktop:Folder 1:Folder 2:"

tell application "Finder"
	duplicate fontCollection to fontDestination
end tell

… which basically involved removing ‘Volumes’ from the start of the source variable name. I ran the script using the select source/destination method mentioned in my last post, and checked the output to see what was going on: that’s when I saw that ‘Volumes’ wasn’t mentioned, so I took it out.

I have used variables elsewhere that include ‘Volume’ at the start, but no errors have been thrown up. Can anyone explain, in simple terms, why the error occurs with the inclusion of “Volumes”?

You’re mixing HFS/Macintosh path with posix path

it’s


set fontCollection to "server:Pictures:ImageAssets:Document Fonts:"
--or
set fontCollection to posix file "/Volumes/server/Pictures/ImageAssets/Document Fonts/"

for desktop the same mistake has made it’s:

set fontDestination to path to desktop folder

Hi,

some problems:
AppleScript doesn’t know what a tilde is and the Finder cannot handle POSIX paths
A HFS path starts always with a disk name (never with the folder /Volumes)
The Finder cannot copy literal strings, a specifier keyword must be added.


set fontCollection to "server:Pictures:ImageAssets:Document Fonts:"
set fontDestination to "~:Desktop"

tell application "Finder"
	duplicate folder fontCollection to desktop
end tell

If the destination folder is a subfolder of desktop, use this syntax


set fontCollection to "server:Pictures:ImageAssets:Document Fonts:"
set fontDestination to ((path to desktop as text) & "Subfolder:")

tell application "Finder"
	duplicate folder fontCollection to folder fontDestination
end tell


I see.

The tilde and Desktop location was just for example “ the actual location is a nested folder, referenced with a full path created by combining other variables input in the script.

I noticed that if I use ‘as alias’ when defining a variable I get an error if the server isn’t connected, yet if I simply use the following (including ‘Volumes:’) at the beginning, I don’t.

set assetFolder to "Volumes:server:Pictures:ImageAssets:The folder:"

Note that I’m using Volumes (HFS), but with colons “ I take it I should remove ‘Volumes:’ from all my variables in the script.

How come my usage of ‘Volumes:’ doesn’t throw up an error elsewhere, when these variables are called? Or is that just luck!

Indeed it’s just luck.
As mentioned above, never ever use a HFS path (colon separated) which starts with “Volumes”.
The HFS path of the folder Volumes is actually “<name of startup volume>:Volumes”

Check the server with a try block whether it’s available, in the error branch you could mount it


try
	"server" as alias -- throws an error if the volume does not exist
on error
	-- mount volume
end try

Excellent, thank you. I do have a server check elsewhere, but I’ll move it to the head of the script so I can define my path variables without errors.

Many thanks … it’s almost all starting to make sense!