AppleScript to Choose Files from Folder Automatically
The way you handle dropping files onto an AppleScript application is like this:

on open theFolders
    -- do your stuff here
end open


You're dropping a folder, or maybe more than one folder. So there needs to be a repeat in there to handle the dropped items, and then another repeat to handle the items inside each of the dropped items. Like this:

on open theFolders
    tell application "Finder"
        repeat with aFolder in theFolders
            set theFolderName to name of aFolder
            set theFiles to every file of aFolder
            --
            repeat with aFile in theFiles
                set theName to name of aFile
                set theNameLength to length of theName
                set theExtension to name extension of aFile
                set theExtensionLength to length of theExtension
                set thePureNameLength to theNameLength - theExtensionLength
                set theName to (characters 1 through thePureNameLength) of theName as string
                set the name of aFile to the last word of theFolderName &amp; "_" &amp; theName &amp; "." &amp; theExtension
            end repeat
            --
        end repeat
    end tell
end open


I think this does what you want. I don't know what your original file names look like, nor what your folder names look like, but for a case where your folder names look like this:

Folder A, Folder B, Folder C

and where the contents of each folder look like this:

file 1.jpg, file 2.jpg, file 3.jpg

The above droplet would give the following results:

For Folder A

A_file 1.jpg, A_file 2.jpg, A_file 3.jpg

For Folder B

B_file 1.jpg, B_file 2.jpg, B_file 3.jpg

For Folder C

C_file 1.jpg, C_file 2.jpg, C_file 3.jpg