AppleScript: how to use a csv list to duplicate & rename an image?
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
Any help would be greatly appreciated!
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
Any help would be greatly appreciated!
Comments
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
Any help would be greatly appreciated!
I can help. First thing you need to specify is how to access the image given only the file name. IOW the path to the image file. Since the image files aren't named the same as the strings in the CSV list, there has to be some other way to locate them.
I can help. First thing you need to specify is how to access the image given only the file name. IOW the path to the image file. Since the image files aren't named the same as the strings in the CSV list, there has to be some other way to locate them.
Sorry, I'm an AppleScript newbie. What does IOW mean?
Just to reiterate my situation...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). I'm not sure if I was clear in my initial description.
Thanks!
Sorry, I'm an AppleScript newbie. What does IOW mean?
Just to reiterate my situation...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). I'm not sure if I was clear in my initial description.
Thanks!
In Other Words.
This seems pretty straightforward. But I need some more details.
1. Where is this template image? Is it a file on the disk somewhere? If so, we need the path to it.
2. Where is the CSV list? Is it a file on the disk somewhere?
Basically, you are going to read the CSV file and then loop duplicating the image file to some directory and renaming it as you indicated.
Applescript can do this easily. The only slightly tricky part is reading the CSV file, but I know how to do that.
Just give me the locations of the data and I will get started on the code.
First, you need to do the following:
1. Substitute the path to your image for my placeholder.
2. Substitute the path to your CSV file for my placeholder.
3. Substitute the path to your Desktop for my placeholder in the path to the "Images" folder.
3. Make a new empty folder on the Desktop and name it Images.
Then run the script. If you turn the volume up you should hear 1098 "dings" as each file is created and moved into the Images folder.
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
NOTE: The forum software put spaces in the filename and at the end of the path in a couple of cases. You'll need to remove them.
I'll give it a shot.
Here's the script.
First, you need to do the following:
1. Substitute the path to your image for my placeholder.
2. Substitute the path to your CSV file for my placeholder.
3. Substitute the path to your Desktop for my placeholder in the path to the "Images" folder.
3. Make a new empty folder on the Desktop and name it Images.
Then run the script. If you turn the volume up you should hear 1098 "dings" as each file is created and moved into the Images folder.
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
NOTE: The forum software put spaces in the filename and at the end of the path in a couple of cases. You'll need to remove them.
Glad to hear it! Was there anything in the code you want explained?
The code is very straightforward. This made me realize that I have absolutely no idea what AppleScript is capable of.
-regards and much thanks for any help
below is my current script-
------------------------------------------------------------------------
set fileRef to open for access alias "MacDaddy HD:Users:kevinvesktop:GMA10Kelly:PARTSGMA10.txt"
set theList to read fileRef using delimiter ","
close access fileRef
tell application "Finder"
\tset theImageFile to alias "StudioArtScratch:Hi-Res"
\tset theFolder to alias "MacDaddy HD:Users:kevinvesktop:GMA10Kelly:HARVEST"
\trepeat with theItem in theList
\t\tset theImageFileCopy to duplicate theImageFile to theFolder
\t\tset name of theImageFileCopy to (theItem as Unicode text)
\tend repeat
end tell
I need to copy all that info to a .jpeg place holder I have and duplicate it. I can get it to generate copies of the jpeg but the fist and last names wont match.
I am using the script listed here then automator to convert to jpeg.
Help Help help.
Sorry if I did not explain it very well.
below is my current script-
------------------------------------------------------------------------
set fileRef to open for access alias "MacDaddy HD:Users:kevinvesktop:GMA10Kelly:PARTSGMA10.txt"
set theList to read fileRef using delimiter ","
close access fileRef
tell application "Finder"
set theImageFile to alias "StudioArtScratch:Hi-Res"
set theFolder to alias "MacDaddy HD:Users:kevinvesktop:GMA10Kelly:HARVEST"
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
Quoting Code: set it up as
...
to keep the colons in tact.
set fileRef to open for access alias "YourDisk:Users:yourHomeFolderesktop:CSVFile.t xt "
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
I'm trying to do something very similar - I need to duplicate a file "file.xml" 400 times and rename each resulting file as a value stored in a CSV list "list.csv"
I've tried to work with the code above, but I really have no idea of what I'm doing. Could someone help? Here's the code I've used so far:
set fileRef to open for access alias "Skynet:list.csv"
set theList to read fileRef using delimiter ","
close access fileRef
tell application "Finder"
\tset theImageFile to alias "Skynet:file.xml"
\tset theFolder to alias "Skynet:result"
\trepeat with theItem in theList
\t\tset theImageFileCopy to duplicate theImageFile to theFolder
\t\tset name of theImageFileCopy to (theItem as Unicode text)
\tend repeat
end tell
When I run it, I copies the file "file.xml" one time, gives one ding, and has copied the file into the folder "result". Can anyone suggest how to change the code so it copies the filename from the file "list.csv" and repeats until it runs out of filenames from "list.csv"?
Any help on this would be GREATLY appreciated -
Thanks
Dan
Basically, I have a list of files named Image_001.tif, Image_002.tiff, etc... and a list of names - can be in CSV or just about any format.
The list of names coordinates with the order of the file list.
I want to rename the photo files with the list of names. Any help is greatly appreciated. Thanks!