I am writing a lightweight file manager and being the lazy programmer that I am, the program is using aesend to send an apple event to the Finder to do file copies and deletions. The problem I have is that I need to know when the copy finishes but I also do not want to wait for it finish either, i.e. I want the file operations to execute in the background. I am using Thomas Tempelmann’s aeSend code, shown below. I’ve tried using MBS’ Carbon Events manager to look for a reply back from Finder but I get nothing.
Anyone have any ideas on how to do this? Am I missing something here?
Thanks!
Phil
#if TargetMacOS
if items.Ubound >= 0 then
dim ae as AppleEvent = NewAppleEvent (“core”, opcode, “MACS”)
dim list as new AppleEventDescList
for each f as FolderItem in items
if f <> nil then
list.AppendFolderItem (f)
end if
next
ae.DescListParam("----") = list
if dest <> nil then
ae.FolderItemParam("insh") = dest
end
if allowInteraction then
declare function AESend lib "Carbon" (ae as Integer, reply as Ptr, sendMode as Integer, prio as Integer, timeoutTicks as Integer, idle as Ptr, filter as Ptr) as Integer
const kAENoReply = &h00000001 ' sender doesn't want a reply to event
const kAEQueueReply = &h00000002 ' sender wants a reply but won't wait
const kAEWaitReply = &h00000003 ' sender wants a reply and will wait
const kAEDontReconnect = &h00000080 ' don't reconnect if there is a sessClosedErr from PPCToolbox
const kAEWantReceipt = &h00000200 ' (nReturnReceipt) sender wants a receipt of message
const kAENeverInteract = &h00000010 ' server should not interact with user
const kAECanInteract = &h00000020 ' server may try to interact with user
const kAEAlwaysInteract = &h00000030 ' server should always interact with user where appropriate
const kAECanSwitchLayer = &h00000040 ' interaction may switch layer
const kAEDontRecord = &h00001000 ' don't record this event - available only in vers 1.0.1 and greater
const kAEDontExecute = &h00002000 ' don't send the event for recording - available only in vers 1.0.1 and greater
const kAEProcessNonReplyEvents = &h00008000 ' allow processing of non-reply events while awaiting synchronous AppleEvent reply
//dim sendMode as Integer = kAEWaitReply+kAEAlwaysInteract+kAECanSwitchLayer -> original code I modified to use different flags
dim sendMode as integer=kAEAlwaysInteract+kAEQueueReply
// Issue the command to the Finder
dim err as Integer = AESend (ae.Ptr, nil, sendMode, 0, 0, nil, nil)
if err <> 0 then
break
return "Could not communicate with Finder (error "+Str(err)+")"
end