Hi Folks,
I wrote an easy file manage AppleScript (AppleScript 1) to move files from shared folder by NSFileManager’s moveItemAtURL: toURL: error: method. Moving files from other user via network cased privilege related error.
So, I changed it to Finder version (AppleScript 2).
Can we avoid such a error when we use NSFileManager ?
<AppleScript 1> on moveFilesWithPOSIXstrList(aFileList, toFolStr) set pathString to current application's NSString's stringWithString:toFolStr set newPath to pathString's stringByExpandingTildeInPath() set defM to current application's NSFileManager's defaultManager repeat with i in aFileList if (defM's isReadableFileAtPath:i) as boolean = true then set fromPath to (current application's |NSURL|'s fileURLWithPath:i)
set fileName to fromPath's lastPathComponent() set newPathStr to (newPath's stringByAppendingPathComponent:fileName) set toPath to (current application's |NSURL|'s fileURLWithPath:newPathStr)
(defM's moveItemAtURL:fromPath toURL:toPath |error|:(missing value)) —Error!! (result was false not true)
else log {"Can not get file”}—not caught here end if end repeat end moveFilesWithPOSIXstrList </AppleScript 1>
<AppleScript 2> on moveFilesWithPOSIXstrList(aFileList, toFolStr) set pathString to current application's NSString's stringWithString:toFolStr set newPath to pathString's stringByExpandingTildeInPath() set targFol to newPath as text
set aliasList to {} repeat with i in aFileList try set the end of aliasList to (POSIX file i) as alias on error
end try end repeat
set targFolAlias to (POSIX file targFol) as alias
try with timeout of 3600 seconds tell application "Finder" move aliasList to targFolAlias with replacing end tell end timeout end try end moveFilesWithPOSIXstrList </AppleScript 2>
|