New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

How can I rename a file with a drag and drop process, using a list as my source data?


Post Reply New Thread Subscribe

 
Thread Tools
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
Hi, I'm looking for a way to automatically rename files using a drag and drop process using OS X. My idea is this:

- I have several video files called, i.e.
10025.mov
10026.mov

Also, I always have a master list of each number and its description. The list is an Excel file that I am able to pull from a program pretty quickly, and it provides the number in the A column, and the description in the B column, like this:

10025 DOOR CLOSEUP 10S
10026 DRIVEWAY 101
10027 DRIVEWAY 102
10028 LICENSE PLATE
10029 GARAGE DOOR

What I want to do is drag files like 10025.mov onto this script/droplet, and it would rename it as "10025_door closeup 10s.mov"

My question is, does anyone know how to do this? The script would have to identify "10025" and find that particular row in the Excel document- then rename the file with an underscore, then the description from the B column. If necessary (since I don't have Excel on my Mac) I could also use a .txt file instead of Excel if that makes it easier. Any insight or Applescript ideas would be greatly appreciated. Thanks
QUOTE Thanks
MacGrunt

 
MacGrunt's Avatar
 
Member Since: Aug 02, 2011
Posts: 17
MacGrunt is on a distinguished road

MacGrunt is offline
G'day

i wrote a script which does something similar to what you're looking for. but it starts off with one column of original names and one column for the new names.

it works on folders of files rather than as a droplet but it might be a good starting point for you RenameByList . it wouldn't be too hard to adapt it for your specific workflow.

for the script as it is, you'd have to adapt your excel file you could use excel's concatenate feature to get your column of new names (number, undescore, description)

hope it helps

m.
QUOTE Thanks
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
Thanks MacGrunt for looking into this. I like the script that you have written. However, it still won't work with all the elements in the same folder, for some reason. It's saying ":" can't be found.

This does appear to be a good starting point for me though. Do you know if it's possible to run this without opening Excel? If not, would a txt file work? (it would have about 5 spaces between column A and column B)

Also, can the script refer to a list which is saved at a specified network path? The .mov files would be in a local folder, and my list would be in a network path. Also, the script itself would need to be in a separate local folder too.

Let's say that we call our network folder with the list SMB://FOLDER PATH FOR LIST/LIST NAME.TXT
Let's call our local folder with the .mov files LOCAL FOLDER WITH QUICKTIME FILES/SUBFOLDER.

Where would these all caps reference names go in your original script?

I know I'm throwing a lot out there... Many thanks for your help already, and any more insight would be greatly appreciated.

Jeff
QUOTE Thanks
MacGrunt

 
MacGrunt's Avatar
 
Member Since: Aug 02, 2011
Posts: 17
MacGrunt is on a distinguished road

MacGrunt is offline
G'day again

Sorry, I missed the bit about how you don't have Excel.

OK, if you're able to export the list as a .csv (comma delimited) file then you could do something like this :

Code:
set mgOriginalNames to {}
set mgNewNames to {}

tell application "Finder"
	set mgTheList to "Colon:Delimited:Path:ToYour:ListFile.csv" as alias
	set mgFolderPath to "Colon:Delimited:Path:ToYour:Folder:" as alias
end tell

open for access mgTheList
set mgList to (read mgTheList)
close access mgTheList

tell application "Finder"
	-- split original list into two lists
	set text item delimiters of AppleScript to ","
	repeat with x from 1 to count paragraphs of mgList
		set end of mgOriginalNames to text item 1 of paragraph x of mgList
		set end of mgNewNames to text item 2 of paragraph x of mgList
	end repeat
	set text item delimiters of AppleScript to ""
	-- get the folder items
	tell application "Finder"
		set mgItems to items of (mgFolderPath as alias)
	end tell
	-- check name and rename if match is found
	repeat with mgItem in mgItems
		set mgName to name of mgItem
		set mgExt to name extension of mgItem
		if mgExt is not "" then set mgExt to "." & mgExt
		set text item delimiters of AppleScript to {"."}
		set mgOldName to text item 1 of mgName
		set text item delimiters of AppleScript to ""
		repeat with x from 1 to count items in mgOriginalNames
			if mgOldName = item x of mgOriginalNames then
				set mgNewName to item x of mgOriginalNames & "_" & item x of mgNewNames
				tell application "Finder"
					set name of mgItem to (mgNewName & mgExt)
				end tell
			end if
		end repeat
	end repeat
end tell
If you can only use a .txt file, you'll have to know exactly how many spaces between entries ('about 5' won't help you). Then relace the comma in this line — set text item delimiters of AppleScript to "," — with that number of spaces

At the top of that script there's a place for you to enter a "Colon:Delimited:Path:To... " for the list file and the folder containing the files to rename. The easiest way to get this path is to have the file or folder selected in the Finder and then run this script from Script Editor :
Code:
tell application "Finder"
	get selection as alias
end tell
Then just copy and paste the quoted path from the Result window into the appropriate place in the main script.

Note that the script in its current form doesn't have any sort of filter to only deal with .mov files — it will rename any files or folders stored in that folder you specify.

To change the all caps to lower case you could run the whole lot through the Rename Finder Items action in Automator.

Hope that helps

m.
QUOTE Thanks
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
That's definitely the right direction- this may work after all! The script was able to find my list file and see the text inside. I could tell from the Applescript summary. However, I got this error even after experimenting with both csv and txt files:
----> "Can't get text item 2 of \"10000 AMBASSADOR 2 \"." number-1728 from text item 2 of "10000 AMBASSADOR 2"

I should mention that the first column was my original filenames (the first entry being 10000)
...and the 2nd column was the new names (the first entry being AMBASSADOR 2 - without the quotes)

Have you heard of this error message?

Another question...
I had these four QuickTimes in the destination folder (in which the file names would be changed):
14751.mov
AEF_NTSC 486 ProRes.mov
SPBBLANT1039.mov
SP WHI2KITNPR59.mov
SP WHEHE.mov

I really only needed 14751 changed at the moment, for my test. Would you anticipate the script being able to ignore the last four because they don't match anything on the list?

Thanks so much for your help so far,

Jeff
QUOTE Thanks
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
I should also mention that when it gave me the error message, it would highlight this line of the script:

"set end of mgNewNames to text item 2 of paragraph x of mgList"
QUOTE Thanks
MacGrunt

 
MacGrunt's Avatar
 
Member Since: Aug 02, 2011
Posts: 17
MacGrunt is on a distinguished road

MacGrunt is offline
I would have expected a csv to render the first line as "10000,AMBASSADOR 2" not "10000 AMBASSADOR 2". If there's only one space between the two elements we'll have to tackle it slightly differently.

Upload your txt file Jeff. Hopefully I'll get a chance to look at it again tonight.

To your other question yes, files with no match get ignored. That's what we're doing here :
Code:
repeat with x from 1 to count items in mgOriginalNames
if mgOldName = item x of mgOriginalNames then ...
That is, if mgOldName matches nothing in mgOriginalNames then do nothing and move on

m.
QUOTE Thanks
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
Hi MacGrunt:

I use a data transfer program from our company's database to creat the list, and it gives different options for what type of text is used. I can also change the extension to create a different file type when I export.

I have attached two examples. The name of each shows which "text/file type option" I chose.

At the moment I am trying to figure out a way to make my 2nd column = (house number) + (title) so that I don't get rid of the number when renaming. If there's a way to do this in the Applescript then great - otherwise I can probably figure out a more practical export option.

Jeff
Attached Files
File Type: txt Comma Separated Variable option.txt (345 Bytes, 2 views)
File Type: txt ASCII text option.txt (345 Bytes, 2 views)
QUOTE Thanks
MacGrunt

 
MacGrunt's Avatar
 
Member Since: Aug 02, 2011
Posts: 17
MacGrunt is on a distinguished road

MacGrunt is offline
G'day Jeff

Using your ASCII text file will be OK but for some reason it's failing at the END of that repeat loop that builds the two lists. We should be able to get over that by adding a try statement.

Here's the replacement for the section immediately after "tell application "Finder" :
Code:
	-- split original list into two lists
	set text item delimiters of AppleScript to "     "
	repeat with x from 1 to count paragraphs of mgList
		try
			set end of mgOriginalNames to text item 1 of paragraph x of mgList
			set end of mgNewNames to text item 2 of paragraph x of mgList
		end try
	end repeat
	set text item delimiters of AppleScript to ""
As it stands, the script will keep both the number and the new name (with an underscore between). That's what this line is doing :
set mgNewName to item x of mgOriginalNames & "_" & item x of mgNewNames

hope that gets you closer

m.
QUOTE Thanks
Feee99

 
Member Since: Oct 13, 2011
Posts: 15
Feee99 is on a distinguished road

Feee99 is offline
It didn't just get closer- it worked exactly as I wanted it to! Thanks a million for this.
QUOTE Thanks

Post Reply New Thread Subscribe


« Leopard Samba Sharing Problems | How to remove a hidden account »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
HELP - when you replace an existing file by drag and drop where does the original go? zylidan Apple Desktops 4 12-31-2010 06:15 AM
Drag and drop to overwrite? (a GUI version of the 'cp' command?) Disco Patrick OS X - Operating System 0 09-18-2010 01:34 PM
Help me with drag and drop ceejay Switcher Hangout 27 09-05-2010 12:18 AM
Firefox users: extension that allows you to drag 'n' drop to upload remain OS X - Apps and Games 4 06-18-2007 01:16 AM
HP PhotoSmart 2575 Driver hana2004 OS X - Operating System 2 05-03-2006 07:03 PM

All times are GMT -4. The time now is 10:34 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?