|
|
AppleScript: how to use a csv list to duplicate & rename an image?
|
|
|
|
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status:
Offline
|
|
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
|
|
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!
|
|
|
|
|
|
|
|
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status:
Offline
|
|
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)
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2006
Location: Back in the Good Ole US of A
Status:
Offline
|
|
Keda,
What's the exact format of the csv file?
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status:
Offline
|
|
it is a plain text csv that was exported from numbers.
|
|
|
|
|
|
|
|
|
Moderator
Join Date: Oct 2001
Location: San Jose, CA
Status:
Offline
|
|
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!
|
|
|
|
|
|
|
|
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status:
Offline
|
|
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
|
|
Can you let everybody know how you solved your problem?
Steve
|
Celebrating 10 years and 4000 posts on MacNN!
|
|
|
|
|
|
|
|
Senior User
Join Date: Dec 1999
Location: Alexandria, VA USA
Status:
Offline
|
|
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:yourHomeFolder esktop:CSVFile .txt "
set theList to read fileRef using delimiter ","
close access fileRef
tell application "Finder"
set theImageFile to alias "YourDisk:Users:yourHomeFolder esktop:Image.j pg"
set theFolder to alias "YourDisk:Users:yourHomeFolder esktop: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)
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2006
Location: Back in the Good Ole US of A
Status:
Offline
|
|
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"
############################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|