• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Renaming a copied file with Finder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Renaming a copied file with Finder


  • Subject: Re: Renaming a copied file with Finder
  • From: Christopher Nebel <email@hidden>
  • Date: Mon, 9 Oct 2006 09:27:02 -0700

On Oct 9, 2006, at 7:29 AM, Yvan KOENIG wrote:

Best as I can tell, you can't do it directly. Here is my work around.

set file_to_copy to (choose file)
set target_folder to (choose folder)
tell application "Finder"
try
duplicate file_to_copy to target_folder without replacing
on error msg number num
if num is -15267 then
set new_name to display dialog msg & " Please choose another name for the copy." default answer (name of file_to_copy) & " copy"
set new_file to duplicate file_to_copy
move new_file to target_folder
else
display dialog msg
end if
end try
end tell

and what if (name of file_to_copy) & " copy" already exists ? ;-)

It's irrelevant, because that block will never be executed. The Finder's "duplicate" command (without replacing) will rename the new file as necessary ("foo copy n") to avoid a collision. ("How do I get a reference to the new file if I don't know its name?", you ask? "Duplicate" returns a reference to the new file as its result.)



--Chris Nebel AppleScript Engineering

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Renaming a copied file with Finder
      • From: Michelle Steiner <email@hidden>
    • Re: Renaming a copied file with Finder
      • From: Timothy Bates <email@hidden>
    • Re: Renaming a copied file with Finder
      • From: Simon Forster <email@hidden>
References: 
 >Renaming a copied file with Finder (From: ishmael <email@hidden>)
 >Re: Renaming a copied file with Finder (From: Michelle Steiner <email@hidden>)
 >Re: Renaming a copied file with Finder (From: Yvan KOENIG <email@hidden>)

  • Prev by Date: Re: Creating an environment variable from AppleScript
  • Next by Date: Re: Backlight using GUI scripting doesn't work...
  • Previous by thread: Re: Renaming a copied file with Finder
  • Next by thread: Re: Renaming a copied file with Finder
  • Index(es):
    • Date
    • Thread