• 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: Finder "duplicate" requirements
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finder "duplicate" requirements


  • Subject: Re: Finder "duplicate" requirements
  • From: Shane Stanley <email@hidden>
  • Date: Sun, 28 Jun 2015 21:52:44 +1000

Chris has given you some good general advice, but as you are using ASObjC, and you have POSIX paths, there's really no reason to use the Finder or any other app -- you might as well do the copy directly.

So something like this:

use scripting additions
use framework "Foundation"

on copyFileAt:POSIXPath toFolder:folderPath withReplacing:replaceFlag
set fileURL to current application's class "NSURL"'s fileURLWithPath:POSIXPath
set folderURL to current application's class "NSURL"'s fileURLWithPath:folderPath
-- build path for new file
set theName to fileURL's lastPathComponent()
set newFileURL to folderURL's URLByAppendingPathComponent:theName
set fileManager to current application's NSFileManager's defaultManager()
set theResult to fileManager's copyItemAtURL:fileURL toURL:newFileURL |error|:(missing value)
if not (theResult as boolean) and replaceFlag then
fileManager's removeItemAtURL:newFileURL |error|:(missing value)
-- or move to Trash: fileManager's trashItemAtURL:newFileURL resultingItemURL:(missing value) |error|:(missing value)
set theResult to fileManager's copyItemAtURL:fileURL toURL:newFileURL |error|:(missing value)
end if
return (theResult as boolean)
end copyFileAt:toFolder:withReplacing:

its copyFileAt:"/Users/shane/Desktop/Testing.png" toFolder:"/Users/shane/Desktop/Test Folder" withReplacing:true

If you want an atomic copy it's a little trickier, but still doable. 

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Finder "duplicate" requirements (From: Jean-Christophe Helary <email@hidden>)
 >Re: Finder "duplicate" requirements (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: Re: Finder "duplicate" requirements
  • Next by Date: sdef etiquette
  • Previous by thread: Re: Finder "duplicate" requirements
  • Next by thread: Re: Finder "duplicate" requirements
  • Index(es):
    • Date
    • Thread