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 > macOS > 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
Keda
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status: Offline
Reply With Quote
May 8, 2008, 09: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!
     
ibook_steve
Moderator
Join Date: Oct 2001
Location: San Jose, CA
Status: Offline
Reply With Quote
May 8, 2008, 12:31 PM
 
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
Celebrating 10 years and 4000 posts on MacNN!
     
Keda  (op)
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status: Offline
Reply With Quote
May 8, 2008, 12:32 PM
 
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)
     
Atheist
Mac Elite
Join Date: Sep 2006
Location: Back in the Good Ole US of A
Status: Offline
Reply With Quote
May 8, 2008, 12:36 PM
 
Keda,
What's the exact format of the csv file?
     
Keda  (op)
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status: Offline
Reply With Quote
May 8, 2008, 12:41 PM
 
it is a plain text csv that was exported from numbers.
     
ibook_steve
Moderator
Join Date: Oct 2001
Location: San Jose, CA
Status: Offline
Reply With Quote
May 8, 2008, 02: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
Celebrating 10 years and 4000 posts on MacNN!
     
Keda  (op)
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status: Offline
Reply With Quote
May 8, 2008, 03:14 PM
 
Thank you all who helped me out. I was able to get this problem solved.

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

Steve
Celebrating 10 years and 4000 posts on MacNN!
     
Keda  (op)
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status: Offline
Reply With Quote
May 9, 2008, 04: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 04:45 PM. Reason: This code thing is messed-up)
     
Atheist
Mac Elite
Join Date: Sep 2006
Location: Back in the Good Ole US of A
Status: Offline
Reply With Quote
May 9, 2008, 05: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
Top
Privacy Policy
All times are GMT -4. The time now is 09:01 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,