PDA

View Full Version : Replace a file




Applescripter
Apr 27, 2012, 02:54 PM
:apple: Hi, I wannt to make an Apllescriptsapp( with Applescript Editor) in which you can make an image to dublicate it with 3 different names ( In the end you have 4 times the same picture with 4 different names). Well, the app should also be able to replace the pics if there were any with the same name before there, but it didn't worked so well right now. Can somebody give me the right code to do that?
Thx



property destination : "Dance" as alias -- the folder to copy to
property nameList : {"blabla", "dudada", "gsasy"}
on run -- application double-clicked or script run from the Editor
open (choose file with multiple selections allowed)
end run


on open theseItems -- items dropped onto the application
"replacing:true"
repeat with anItem in theseItems -- go through all the dropped items
repeat with aName in nameList -- go through all the names
tell application "Finder" -- make a copy and rename
set name of (((duplicate anItem to destination) to aName) with replacing)
end tell
"replacing:true"
end repeat
end repeat
end open



kryten2
Apr 27, 2012, 03:41 PM
it didn't worked so well
Is a bit of an understatement but at least you tried.

property destination : "Dance" as alias -- the folder to copy to

needs to point to a location in the form of :

"Macintosh HD:Users:yourusername:Documents:Dance"

Your on run handler opens a choose file dialog and does nothing else. If you want to work with theseItems change to :

set theseItems to (choose file with multiple selections allowed)
The on open handler contains errors as well. It will be much more rewarding if you find the solution yourself. You'll gain valuable knowledge by doing so. Work on it a bit more and if you get stuck again post the code.

Red Menace
Apr 27, 2012, 03:59 PM
If you also want to duplicate the original file without renaming it, just add another Finder duplicate command after the first repeat statement. Take a look at the Finder's scripting dictionary for information about the duplicate command - "replacing:true" isn't going to do anything.

Edit: forgot that the script copies first and then renames, so the additional duplicate command for the original item would go after duplicating and renaming for the other names (between the end repeat statements).