Search code examples
applescript

error "Finder got an error: Handler can’t handle objects of this class." number -10010


I am trying to create a folder on desktop from random number than trying to delete it.

set my_number to random number 100

set my_number to my_number as text

set folder_name to "Folder number" & my_number

tell application "Finder" to make new folder at desktop

set my_folder to the result as alias

tell application "Finder" to set the the name of my_folder to folder_name

display dialog ("Delete new folder " & folder_name & "??") buttons {"YES", "NO"}

set dialog_command_record to the result

if button returned of dialog_command_record is "YES" then
    
    
    tell application "Finder" to delete my_folder
    
end if

But getting error:

`error "Finder got an error: Handler can’t handle objects of this class." number -10010`

Solution

  • move it to the trash as you would do manually

    set my_number to (random number 100) as text
    set folder_name to "Folder number " & my_number
    tell application "Finder" to set my_folder to make new folder at desktop with properties {name:folder_name}
    set dialog_command_record to display dialog ("Delete new folder " & folder_name & "??") buttons {"YES", "NO"} default button "YES"
    if button returned of dialog_command_record is "YES" then tell application "Finder" to move my_folder to trash