hI
I use the below to delete items when dropped onto an area in my project, it will only allow me to delete one file or one folder at a time, how can I have the code allow multiple items to be deleted at once?
-------------------------------
on draggingEntered_(info)
return current application's NSDragOperationCopy
end draggingEntered_
on draggingExited_(info)
mainTrashWindow's makeFirstResponder_(missing value)
end draggingExited_
on performDragOperation_(info)
set pb to info's draggingPasteboard()
set theURLs to pb's propertyListForType_("NSFilenamesPboardType")
performSelector_withObject_afterDelay_("doFinderStuff:", theURLs, 0.1)
return true
end performDragOperation_
-----------------------------------------------
-- TRASH 1
-----------------------------------------------
on doFinderStuff_(theURLs)
set FileToDelete to theURLs as string as POSIX file
tell application "Finder"
delete FileToDelete
end tell
end doFinderStuff
------------------------------------------------
--
------------------------------------------------
thanks Shane
I got to this stage, i think it’s right , as it will accept a file and trash it, but it still only trashes one file, not multiple files, did i miss something?
on performDragOperation:info
set pb to info's draggingPasteboard()
set theURLs to pb's readObjectsForClasses:{current application's NSURL} options:(missing value)
set theURLs to pb's propertyListForType:"NSFilenamesPboardType"
performSelector_withObject_afterDelay_("doFinderStuff:", theURLs, 0.1)
return true
end performDragOperation:
on doFinderStuff:theURLs
set FileToDelete to theURLs as string as POSIX file
set fileManager to current application's NSFileManager's defaultManager()
fileManager's trashItemAtURL:(FileToDelete) resultingItemURL:(missing value) |error|:(missing value)
end doFinderStuff:
You’re getting URLs and the trash method wants a URL, so you just need a simple repeat loop:
on doFinderStuff:theURLs
set fileManager to current application's NSFileManager's defaultManager()
repeat with aURL in theURLs
(fileManager's trashItemAtURL:aURL resultingItemURL:(missing value) |error|:(missing value))
end repeat
end doFinderStuff:
thanks Shane
been trying to get this to work, but all I get back is errors, I cant seem to figure out what the problem is
just dropping one file returns the below
I have played around with different variations, pretty well much the same result as above
on doFileManagerStuff:theURLs
set fileManager to current application's NSFileManager's defaultManager()
repeat with aURL in theURLs
--try
tell the fileManager to trashItemAtURL:aURL resultingItemURL:(missing value) |error|:(missing value)
--end try
end repeat
end doFileManagerStuff:
It looks like you haven’t made the earlier change:
on performDragOperation:(info)
set pb to info's draggingPasteboard()
set theURLs to pb's readObjectsForClasses:{current application's NSURL} options:(missing value)
performSelector_withObject_afterDelay_("doFinderStuff:", theURLs, 0.1)
return true
end performDragOperation_