Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rename images (optional add comments)



On 11/17/06, Jan Bultereys <email@hidden> wrote:
 What I have is an excel file:
 Column A: old name
 Column B: New name

I might recommend saving that spreadsheet in a simple text format like CSV, so that your rename script can open and read it without having to fire up Excel.

But here's a sample script to get you started:

---

set dataFile to (choose file with prompt "Where is the list of names
to change?") as alias

set folderName to (choose folder with prompt "Where are the files to
be renamed?") as alias

tell application "Microsoft Excel"
	open dataFile
end tell

set curRow to 1
set done to false
repeat while not done

	tell application "Microsoft Excel"
		tell active sheet of active workbook
			set oldName to (get value of (cell ("A" & curRow)))
			if oldName is "" then
				set done to true
			else
				set newName to (get value of (cell ("B" & curRow)))
			end if
		end tell
	end tell

	if not done then
		tell application "Finder"
			try
				set targetFile to (file oldName) of (folderName) as alias
				set name of targetFile to newName
			on error number -1700
				-- do nothing; file doesn't exist
			end try
		end tell
	end if

	set curRow to curRow + 1
end repeat

tell application "Microsoft Excel"
	close active workbook
end tell
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden
References: 
 >Rename images (optional add comments) (From: Jan Bultereys <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.