Applescript troubleshooting

Joined
Jul 12, 2011
Messages
2
Reaction score
0
Points
1
I have a folder of 258 excel files that are sorted alphabetically. I would like to run a script that renames all of the files based on excel values. I wrote a script that does a similar action, but to add new folders based on excel content. I tried to adapt it, but I was unsuccessful. Can anyone help?
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Can you post the script? It's likely that it can be adapted with some minor changes.
 
OP
T
Joined
Jul 12, 2011
Messages
2
Reaction score
0
Points
1
set theFiles to choose file with multiple selections allowed
set theCount to number of items in theFiles
repeat with i from 1 to theCount
tell application "Microsoft Excel"
set theCells to value of range "a1:a71" of active sheet
end tell
repeat with onecell in theCells

tell application "Finder"


set name of file (item i of theFiles) to (item 1 of onecell)

end tell
end repeat
end repeat
 
Joined
Aug 2, 2011
Messages
16
Reaction score
0
Points
1
G'day

I'm assuming you are trying to rename a bunch of files using one open excel spreadsheet as the source of the filenames — and that the new filenames are in column A (?)

Code:
set theFiles to choose file with multiple selections allowed
set NewNames to {}

--place enough values from excel file into a list
tell application "Microsoft Excel"
	tell active sheet of active workbook
		repeat with x from 1 to count of theFiles
			set end of NewNames to formula of cell ("A" & x)
		end repeat
	end tell
end tell
--rename the files
repeat with i from 1 to count of theFiles
	set NewName to item i of NewNames
	set ThisFile to item i of theFiles
	tell application "Finder"
		set name of ThisFile to (NewName & "." & name extension of ThisFile)
	end tell
end repeat

i haven't tested what will happen if the script runs into an empty cell.

you could also run this as a droplet instead by changing it like this :
Code:
on open theFiles
	-- delete the following line
	set theFiles to choose file with multiple selections allowed
	--add the rest of the script
end open

hope that helps a little

m.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top