| OS X - Operating System General OS operation information and support |
| Post Reply | New Thread | Subscribe |
|
|
Thread Tools |
![]() Member Since: Oct 13, 2011
Posts: 15
![]() |
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 | |
![]() Member Since: Aug 02, 2011
Posts: 17
![]() |
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 | |
![]() Member Since: Oct 13, 2011
Posts: 15
![]() |
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 | |||||
![]() Member Since: Aug 02, 2011
Posts: 17
![]() |
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
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 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 | |
![]() Member Since: Oct 13, 2011
Posts: 15
![]() |
----> "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 | |
![]() Member Since: Aug 02, 2011
Posts: 17
![]() |
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 ... m. |
| QUOTE Thanks | |
![]() Member Since: Oct 13, 2011
Posts: 15
![]() |
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 |
| QUOTE Thanks | |
![]() Member Since: Aug 02, 2011
Posts: 17
![]() |
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 "" set mgNewName to item x of mgOriginalNames & "_" & item x of mgNewNames hope that gets you closer m. |
| QUOTE Thanks | |
| Post Reply | New Thread | Subscribe |
| Thread Tools | |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
|||||||
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 05:15 AM |
| Drag and drop to overwrite? (a GUI version of the 'cp' command?) | Disco Patrick | OS X - Operating System | 0 | 09-18-2010 12:34 PM |
| Help me with drag and drop | ceejay | Switcher Hangout | 27 | 09-04-2010 11:18 PM |
| Firefox users: extension that allows you to drag 'n' drop to upload | remain | OS X - Apps and Games | 4 | 06-18-2007 12:16 AM |
| HP PhotoSmart 2575 Driver | hana2004 | OS X - Operating System | 2 | 05-03-2006 06:03 PM |
All times are GMT -4. The time now is 12:33 AM.
Powered by vBulletin