Results 1 to 10 of 10
  1. #1


    Member Since
    Oct 13, 2011
    Posts
    15
    How can I rename a file with a drag and drop process, using a list as my source data?
    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

  2. #2

    MacGrunt's Avatar
    Member Since
    Aug 02, 2011
    Posts
    16
    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.

  3. #3


    Member Since
    Oct 13, 2011
    Posts
    15
    Thank you
    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

  4. #4

    MacGrunt's Avatar
    Member Since
    Aug 02, 2011
    Posts
    16
    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.

  5. #5


    Member Since
    Oct 13, 2011
    Posts
    15
    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

  6. #6


    Member Since
    Oct 13, 2011
    Posts
    15
    additonal note
    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"

  7. #7

    MacGrunt's Avatar
    Member Since
    Aug 02, 2011
    Posts
    16
    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.

  8. #8


    Member Since
    Oct 13, 2011
    Posts
    15
    Text file samples
    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 Attached Files

  9. #9

    MacGrunt's Avatar
    Member Since
    Aug 02, 2011
    Posts
    16
    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.

  10. #10


    Member Since
    Oct 13, 2011
    Posts
    15
    It didn't just get closer- it worked exactly as I wanted it to! Thanks a million for this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. drag and drop
    By paul ruszel in forum OS X - Operating System
    Replies: 1
    Last Post: 07-31-2012, 05:12 PM
  2. Excel 2008 - Data Validation Drop-down List
    By Kirstie007 in forum OS X - Apps and Games
    Replies: 1
    Last Post: 08-04-2011, 01:21 PM
  3. Replies: 4
    Last Post: 12-31-2010, 05:15 AM
  4. Help me with drag and drop
    By ceejay in forum Switcher Hangout
    Replies: 27
    Last Post: 09-04-2010, 11:18 PM
  5. Can not drag and drop
    By adrianmoore in forum OS X - Operating System
    Replies: 2
    Last Post: 05-08-2007, 11:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •