Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

irun5k

macrumors 6502
Original poster
Jan 14, 2005
379
0
I'm having some trouble with an applescript, it is designed to simply let the user select an folder, and then copy a folder from the same directory as the script into the chosen folder (recursively.) This should be dirt simple, but I'm an Applescript n00b :( Both the paths in the error message exist, so I'm probably misunderstanding a command.

Code:
set targetDir to choose folder default location "/Applications" with prompt "Please select the program directory:"

set imageDir to ParentFromPath(path to me, true) & "images"

tell application "Finder"
	copy folder imageDir to folder (targetDir)
end tell


on ParentFromPath(thePath, wantPath)
	set thePath to (thePath as text)
	set saveDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {":"}
	set pathAsList to text items of thePath
	if the last character of thePath is ":" then
		set idx to (the number of text items in thePath) - 2
	else
		set idx to -2
	end if
	if wantPath then
		set folderName to ((text items 1 through idx of pathAsList) as text) & ":"
	else
		set folderName to item idx of pathAsList
	end if
	set AppleScript's text item delimiters to saveDelim
	return folderName
end ParentFromPath

Finder got an error: Can’t set folder (alias "Mac HD:Applications:Test App:") to folder "johndoe:dev:workspace:images".
 
"copy" in AppleScript means to copy the data in one variable into another. The Finder dictionary includes a copy command but it also says it's not supported. Strangely, to do what you want, you need "move."

This doesn't worry about recursion, but it's a basic folder copying script:

Code:
tell application "Finder"
	set sourceFile to choose folder with prompt "Choose a folder to copy:"
	set targetFolder to choose folder with prompt "And where do you want it to go?"
	try
		move sourceFile to targetFolder
	on error errMsg number errNum
		display dialog "Error: " & errNum & return & errMsg
	end try
	update targetFolder
end tell

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.