Help with contextual menu Big Cat script

I’m trying to make a contextual menu Big Cat script that would make a disk imge from folder chosen in Finder.

I’ve problem with this line: do shell script “rm -r '” & dmgPath & “'”
If I add this line - nothing happens.

If I remove the line, I end up with the file named: My image_temp, which is not what I want.

I’m newbie in this do shell script department, so any help would be highly appreciated!

on main(TheFiles)
    repeat with i in TheFiles
        
        set ItemInfo to info for i
        set folderName to name of ItemInfo
        set theDestination to POSIX path of ?
            (choose folder with prompt "Where do you want to save the disk images?")
        set imageName to folderName & "_temp.dmg"
        set theSource to POSIX path of i
        set dmgPath to theDestination & imageName as string
        set shellCommand to "hdiutil create -srcfolder '" & ?
            theSource & "' -tgtimagekey zlib-level=9 '" & dmgPath & "'"
        with timeout of 3600 seconds
            do shell script shellCommand
            do shell script "rm -r '" & dmgPath & "'"
        end timeout
        
    end repeat
end main

Does this work for you?

on main(TheFiles)
    set destinationPath to (choose folder with prompt "Where do you want to save the disk images?") as string
    repeat with i in TheFiles
        set ItemInfo to info for (i as alias)
        set theSource to (quoted form of POSIX path of (i as string))
        set dmgPath to (quoted form of POSIX path of (destinationPath & (name of ItemInfo) & ".dmg"))
        with timeout of (10 * minutes) seconds
            do shell script "hdiutil create -srcfolder " & theSource & " -tgtimagekey zlib-level=9 " & dmgPath
        end timeout
    end repeat
end main

Jon

Yes, fluently!

Thank you!

Using “as alias” in this line; set ItemInfo to info for (i as alias) was surprise for me.

What’s the difference between “POSIX path” and “quoted form of POSIX path” and when I should use which one?

Well, what do know! Apple has a page dedicated to this do shell script thing.
do shell script in AppleScript