Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > AppleScript: how to use a csv list to duplicate & rename an image?

AppleScript: how to use a csv list to duplicate & rename an image?
Thread Tools
Mac Enthusiast
Join Date: Nov 1999
Location: Arlington, VA USA
Status: Offline
Reply With Quote
May 8, 2008, 08:23 AM
 
I have a csv list that contains a series of image names (1AMS2612.jpg, 1AMS2645.jpg, 1AMS7374.jpg, 1AMS7375.jpg, etc) and a single 'placeholder' graphic. I need to use the csv list (well contents of the file...this can be made into another format) to make a copy of the image for each entry in the list, and rename that file to the name of the entry.

Here's what I'm thinking about:
1) Get the first entry from the list (e.g. 1AMS2612.jpg).
2) Make a copy of the image file
3) Rename image file to match the entry's name (e.g. 1AMS2612.jpg)
4) Get second entry, and repeat the process

I thought Automator might do this, but I couldn't make it happen. Are there any AppleScript gurus here? I thought there used to be a sub forum for this, but it looks like it is gone.

Any help would be greatly appreciated!
     
Moderator
Join Date: Oct 2001
Location: San Jose, CA
Status: Offline
Reply With Quote
May 8, 2008, 11:31 AM
 
I'm not at my MBP right now, but if you copy a file from one location to another in the Finder, doesn't the file name stay the same (which appears to be what you want from your example)? The name is only changed if you duplicate within the same folder.

Steve
Guess I finally got that fifth star!
     
Mac Enthusiast
Join Date: Nov 1999
Location: Arlington, VA USA
Status: Offline
Reply With Quote
May 8, 2008, 11:32 AM
 
I have a 'template' image that I need to duplicate 1098 times. Then I need to rename the files to match the listing in the csv. (1AMS2612.jpg, 1AMS2645.jpg, 1AMS7374.jpg, 1AMS7375.jpg, etc)
     
Grizzled Veteran
Join Date: Sep 2006
Location: Sint Maarten, Netherlands Antilles
Status: Online
Reply With Quote
May 8, 2008, 11:36 AM
 
Keda,
What's the exact format of the csv file?
     
Mac Enthusiast
Join Date: Nov 1999
Location: Arlington, VA USA
Status: Offline
Reply With Quote
May 8, 2008, 11:41 AM
 
it is a plain text csv that was exported from numbers.
     
Moderator
Join Date: Oct 2001
Location: San Jose, CA
Status: Offline
Reply With Quote
May 8, 2008, 01:17 PM
 
Have you checked any of the renaming applications to see if any of them will let you read in a file?

Search - VersionTracker

Steve
Guess I finally got that fifth star!
     
Mac Enthusiast
Join Date: Nov 1999
Location: Arlington, VA USA
Status: Offline
Reply With Quote
May 8, 2008, 02:14 PM
 
Thank you all who helped me out. I was able to get this problem solved.

     
Moderator
Join Date: Oct 2001
Location: San Jose, CA
Status: Offline
Reply With Quote
May 8, 2008, 04:21 PM
 
Can you let everybody know how you solved your problem?

Steve
Guess I finally got that fifth star!
     
Mac Enthusiast
Join Date: Nov 1999
Location: Arlington, VA USA
Status: Offline
Reply With Quote
May 9, 2008, 03:37 PM
 
Sure. First of all, Atheist was kind enough to offer to write a script for me, but before he could do that, lundy on AppleInsider posted an AppleScript. Here it is:

Code:
set fileRef to open for access alias "YourDisk:Users:yourHomeFolder:Desktop:CSVFile.txt" set theList to read fileRef using delimiter "," close access fileRef tell application "Finder" set theImageFile to alias "YourDisk:Users:yourHomeFolder:Desktop:Image.jpg" set theFolder to alias "YourDisk:Users:yourHomeFolder:Desktop:Images:" repeat with theItem in theList set theImageFileCopy to duplicate theImageFile to theFolder set name of theImageFileCopy to (theItem as Unicode text) end repeat end tell
Here it is out of the 'code' window, which is not looking the way I'd like it to.
---------------------------------------------
set fileRef to open for access alias "YourDisk:Users:yourHomeFolderesktop:CSVFile .txt "
set theList to read fileRef using delimiter ","
close access fileRef

tell application "Finder"
set theImageFile to alias "YourDisk:Users:yourHomeFolderesktop:Image.j pg"
set theFolder to alias "YourDisk:Users:yourHomeFolderesktop:Images: "
repeat with theItem in theList
set theImageFileCopy to duplicate theImageFile to theFolder
set name of theImageFileCopy to (theItem as Unicode text)
end repeat
end tell
----------------------


It worked well.


*note: extra spaces are being added for some reason.
(Last edited by Keda; May 9, 2008 at 03:45 PM (Reason:This code thing is messed-up))
     
Grizzled Veteran
Join Date: Sep 2006
Location: Sint Maarten, Netherlands Antilles
Status: Online
Reply With Quote
May 9, 2008, 04:45 PM
 
Here's the shell script I threw together:

############################
#!/bin/bash

SOURCE="nophoto.jpg"
CSVFILE="list.csv"

while read line
do
echo "Copying $line"
cp $SOURCE $line
done < $CSVFILE
echo "Done"
############################
     
   
Thread Tools
 
Forum Links
Forum 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 On
Top
Privacy Policy
All times are GMT -5. The time now is 10:40 PM.
All contents of these forums © 1995-2008 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.7.2 © 2000-2008, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.2.0 RC8