• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Rename images (optional add comments)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rename images (optional add comments)


  • Subject: Re: Rename images (optional add comments)
  • From: "Mark J. Reed" <email@hidden>
  • Date: Fri, 17 Nov 2006 10:35:58 -0500

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:
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>)

  • Prev by Date: Filemaker and access/lock/protection
  • Next by Date: Two dumb questions:
  • Previous by thread: Re: Rename images (optional add comments)
  • Next by thread: AppleScript Error
  • Index(es):
    • Date
    • Thread