I have been struggling at the newbie level of Applescript for years, from time to time, on my own. Time to ask for help! I’ve just joined Macscripter.
I would like to write a script that prompts the user to choose a file (from within a predetermined folder, if possible), and then duplicate it to the same destination, then rename the duplicated file to a specific name (and once I have that figured out, move it to a predetermined location).
I’m stuck after the file duplication. How do I refer to the new file so I can rename it?
choose file
set fileChoice to result
tell application "Finder"
duplicate fileChoice
(* What goes here so I can rename the new duplicate? I want to specify what the new name will be, by the way *)
end tell
Thank you! I used your first example and it worked great.
Okay, I’m asking. In this second way, how do you specify the folder and file name you want?
Thanks,
Jessi
p.s. I’m learning cool stuff all the way and am having a great time! Like how to use a do script statement with admin privileges. Yes I’m sure it’s a security risk but I’m just experimenting and I back up regularly.
tell application "Finder"
activate
choose file without invisibles
duplicate (result) to ((path to pictures folder as text) & "example.png") without replacing
end tell
Finder got an error: Handler can’t handle objects of this class.
Also, I should have chosen a different example for the folder. What if I want to save it to somewhere there isn’t a special reference to? Like
/System/Library/myFolder
OK, I know that sounds crazy, but it would be longwinded to explain. Anyway I’d like to know the alternate way to refer to the folder rather than using the built-in special location references, if you have the time to answer that question.
Thanks for all your help, as I am learning a heap!
property newFile : (path to library folder from system domain as text) & "myFolder:example.png"
tell application "Finder"
activate
choose file without invisibles
duplicate (result) to newFile without replacing
end tell