Help Moving Files

I am trying to move files based on an excel sheet. The image name is in column M (13) (I am getting the other values because they will have image names as well. I’m just trying to get one to work at this point.)

I am able to retrieve the image name from the excel file but when I tell finder to duplicate it says it can’t make alias.

I think I’m close, but obviously missing something. Any help is greatly appreciated.

Here’s what I have so far:

property firstColumn : "A"
property LastColumn : "AG"
property firstRow : 2

set myDoc to "HOM_Shortrun:x_Move Images Test:Supermerge.test.xls"
set myFolder to "HOM_Shortrun:x_Move Images Test:Test Destination:"
set sourceFolder to "HOM_Shortrun:x_Move Images Test:Test Source:"
tell application "Microsoft Excel" to open myDoc
set x to firstRow
repeat
	tell application "Microsoft Excel" to set {v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, 25, v26, v27, v28, v29, v30, v31, v32, v33} to item 1 of (get value of range (firstColumn & x & ":" & LastColumn & x))
	if v1 is "" then exit repeat
	if v13 is not "" then set image1 to v13
	tell application "Finder"
		duplicate image1 of sourceFolder as alias to myFolder as alias
	end tell
	set x to x + 1
end repeat

Hi,

try to reference the Finder items by the class keywords file / folder


duplicate file image1 of folder sourceFolder to folder myFolder

Instead of defining lots of variables you can use just a list


.
	tell application "Microsoft Excel" to set valueList to item 1 of (get value of range (firstColumn & x & ":" & LastColumn & x))
	tell valueList
		if item 1 is "" then exit repeat
		if item 13 is not "" then set image1 to item 13
	end tell
.

Thanks very much. That is working except that if the item 13 is empty the finder tries to move the Image from the previous record.

Also, thanks for the tip on using the list. However, I have 2 questions regarding that development. (Thanks for your patience)

A) I was hoping to integrate a previous script that generated a folder based on V1 and V5

repeat
	tell application "Microsoft Excel" to set {v1, v2, v3, v4, v5} to item 1 of (get value of range (firstColumn & x & ":" & nextColumn & x))
	if v1 is "" then exit repeat
	tell application "Finder" to make new folder at myFolder with properties {name:((v1 as text) as text) & "." & v5}
	set x to x + 1
end repeat

I want the files to copy into this new folder. Do I need to stick with Variables, or change V1 and V5 to Item 1 and Item 5, (Which i tried, but didn’t work)

B) Secondly, if I need to move images based on item 13, item 15 and item 32 can I move them to the same folder in one step with a list?

Thanks so much for the assistance: I am trying to wrap my head around applescript.

I haven’t tested this and I’m not sure to put all together but try this


property firstRow : 2

set myDoc to "HOM_Shortrun:x_Move Images Test:Supermerge.test.xls"
set myFolder to "HOM_Shortrun:x_Move Images Test:Test Destination:"
set sourceFolder to "HOM_Shortrun:x_Move Images Test:Test Source:"
tell application "Microsoft Excel" to open myDoc
set x to firstRow
repeat
	tell application "Microsoft Excel"
		tell row x
			set imageNames to {value of cell 13, value of cell 15, value of cell 32}
			set folderName to string value of cell 1 & "." & string value of cell 5
		end tell
	end tell
	if item 1 of imageNames is "" then exit repeat
	tell application "Finder"
		if not (exists folder folderName of folder myFolder) then
			make new folder at folder myFolder with properties {name:folderName}
		end if
		repeat with anItem in imageNames
			if contents of anItem is not "" then
				duplicate file anItem of folder sourceFolder to folder folderName of folder myFolder
			end if
		end repeat
	end tell
	set x to x + 1
end repeat


That is fabulous. Thanks very much. I did have to make a slight change as only cell 1 will never be empty. so the exit had to be based on that.

Here is the final:

property firstRow : 2

set myDoc to "HOM_Shortrun:x_Move Images Test:Supermerge.test.xls"
set myFolder to "HOM_Shortrun:x_Move Images Test:Test Destination:"
set sourceFolder to "HOM_Shortrun:x_Move Images Test:Test Source:"
tell application "Microsoft Excel" to open myDoc
set x to firstRow
repeat
	tell application "Microsoft Excel"
		tell row x
			set imageNames to {value of cell 13, value of cell 15, value of cell 32}
			set folderName to string value of cell 1 & "." & string value of cell 5
			set jobnumber to value of cell 1
		end tell
	end tell
	if jobnumber is "" then exit repeat
	tell application "Finder"
		if not (exists folder folderName of folder myFolder) then
			make new folder at folder myFolder with properties {name:folderName}
		end if
		repeat with anItem in imageNames
			if contents of anItem is not "" then
				duplicate file anItem of folder sourceFolder to folder folderName of folder myFolder
			end if
		end repeat
	end tell
	set x to x + 1
end repeat

Thanks again. This is wicked cool!