move dropped file/folders to the trash?

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

I would think all you have to do is tell the Finder to delete the file paths. Maybe the paths are Posix so convert them to colon delim paths.

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.

Ric

Hi Ric

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.

Ric

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
    

and get this error


The last value should be whatever you want your delay to be, not missing value, and there shouldn’t be a comma at the end

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.

Ric

my bad, it works fine, learning all the time

thanks for your help, appreciate it.

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

See www.macosxautomation.com/applescript/apps/gotchas.html

You can’t use POSIX file as a specifier, only as a coercion.

thanks Shane, that was the problem

	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.