For the archives, I've posted my solution for moving files on OS X that need
authorization. Thanks to Francois Van Lerberghe for the excellent shell tip!

Watch for the returns added by the email...

Function MoveFileAuthorizingAsNeededTo(Extends f as folderitem,
DestinationFolder as folderItem) As boolean
  
  dim res as Boolean
  
  if NOT DestinationFolder.IsWriteable AND TargetMacOS AND NOT
TargetMacOSClassic then
    ' Call AppleScript
    MoveFileWithAuthorization( f.ShellPath, DestinationFolder.ShellPath  )
    
    ' Test Result
    res = DestinationFolder.Child( f.Name ).Exists AND NOT f.Exists
  end if
  
  ' Attempt .MoveFileTo for isWritable, MacClassic, and Win32
  ' if AppleScript was attempted and cancelled or failed, calling
  ' .MoveFileTo will fail and properly set .LastErrorCode.
  
  if NOT res then  
    f.MoveFileTo( DestinationFolder )
    res = (f.LastErrorCode = 0 )
  end if
  
  return res
  
End Function


The AppleScript MoveFileWithAuthorization.scpt is simply:

on run {SourceFile, DestinationFolder}
    do shell script "mv '" & SourceFile & "' '" & DestinationFolder & "' "
    with administrator privileges
end run


Any enhancements are welcome. Thanks to Tom and Francois for their help,

Keith DeLong


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to