Hi
Ive been using this drag and drop script which rdelmar wrote a while back, it works great, im now trying to when files/folders are dropped on a box have them moved to the trash, is their something i need to add to the dragging entered or performDragOperation to make it do what i need?, if so what is it please.
script DROPTRASH
property parent : class "NSBox"
property mainTrashWindow : missing value
-------------------------------
on draggingEntered_(info)
return current application's NSDragOperationCopy
end draggingEntered_
on draggingExited_(info)
mainTrashWindow's makeFirstResponder_(missing value)
end draggingExited_
on performDragOperation_(info)
performSelector_withObject_afterDelay_("doFinderStuff", missing value, 0.1)
return true
end performDragOperation_
-----------------------------------------------
-- TRASH
--------------------
-----------------------------------------------
on doFinderStuff()
--do trash stuff here
end doFinderStuff
------------------------------------------------
--
------------------------------------------------
on awakeFromNib()
my mainTrashWindow's registerForDraggedTypes_({"NSFilenamesPboardType"})
end awakeFromNib
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
In your performDragOperation method you should have the following:
set pb to info's draggingPasteboard()
set theURLs to pb's propertyListForType_("NSFilenamesPboardType")
Then you should pass theURLs as the object in your performSelector:withObject:afterDelay: statement, so your finder methods will know what URL (or URLs) to move to the trash. I would normally do this operation without using theFinder, but I think you need to use the NSWorkspace method recycleURLs:completionHandler: which uses a block, so can’t be used in ASOC.
thanks for your help , I’ve played with this a bit, and can’t get it to work, what would i be doing wrong?
on performDragOperation_(info)
set pb to info's draggingPasteboard()
set theURLs to pb's propertyListForType_("NSFilenamesPboardType")
--display dialog theURLs as string
performSelector_withObject_afterDelay_("doFinderStuff", theURLs, missing value, 0.1)
return true
end performDragOperation_
on doFinderStuff()
display dialog theURLs as string
end doFinderStuff
What result are you getting? Do you get any error messages? One thing wrong I see, is that your selector should have a colon on the end, “doFinderStuff:”, to indicate that it takes one argument (which is the “object” you are passing in the performSelector_ method). Then your method should be doFinderStuff_(theURLs) or whatever else you want to call your argument.
The method name implies three arguments, but you’re trying to provide four. And that selector doesn’t have a colon, so it’s either missing or it doesn’t take an argument.
I’ve changed the code to what i think your saying (novice i am ) probably missed it as im still getting coercion errors
on performDragOperation_(info)
set pb to info's draggingPasteboard()
set theURLs to pb's propertyListForType_("NSFilenamesPboardType")
performSelector_withObject_afterDelay_("doFinderStuff:", theURLs, missing value, )
return true
end performDragOperation_
on doFinderStuff_(theURLs)
log theURLs
end doFinderStuff
sorry, copied the wrong code, was supposed to be this one, even so i still get the above error
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_
on doFinderStuff_(theURLs)
log theURLs
end doFinderStuff
Are you sure? The error message really means argument 3 not 4, but it’s saying it can’t make
‘missing’ into a number, so I don’t know why you should still be getting that error. Try it again to make sure you’re still getting that error.
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_
on doFinderStuff_(theURLs)
log theURLs
end doFinderStuff
I have the drag and drop part working now, just cant get the file that is dropped to be moved to the trash
i’m using this set up, which fails, with this error message, i though this should have worked.
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_
on doFinderStuff_(theURLs)
do shell script "rm " & quoted form of POSIX path of theURLs
end doFinderStuff
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
-----------------------------------------------
on doFinderStuff_(theURLs)
set FileToDelete to theURLs as string as POSIX file
tell application "Finder"
delete FileToDelete
end tell
end doFinderStuff
------------------------------------------------
--
------------------------------------------------
how do I get the performDragOperation_(info) to recognize multiple dropped files?, if that’s the right place, ie: I have selected say 4 or 5 items on the desktop and drag and dropped.