This will take any number of items, and make a folder of the same name, and out the item in it.
So, as an example, you have a file named Movie2013.mp4
You drag this file onto the script, and 2 things happen
A Folder name Movie2013 is created.
The file Movie2013.mp4 is moved into this folder
Enjoy!
on open theDropped
repeat with oneDrop in theDropped
set posixfilepath to (the POSIX path of oneDrop)
set posixfilepathLIST to emptylist(stringtolist(posixfilepath, "/"))
if (last item of posixfilepathLIST) contains ".avi" or (last item of posixfilepathLIST) contains ".mkv" or (last item of posixfilepathLIST) contains ".mov" or (kind of (info for posixfilepath) ≠"Folder") then
--set thename to item 1 of stringtolist(last item of posixfilepathLIST, ".")
set thename to (ListToString((reverse of (rest of (reverse of (stringtolist(last item of posixfilepathLIST, "."))))), "."))
set posixfilepathLISTCLEANED to reverse of (rest of (reverse of posixfilepathLIST))
set posixfilepathSTRINGCLEANED to ListToString(posixfilepathLISTCLEANED, "/")
do shell script "mkdir \"/" & posixfilepathSTRINGCLEANED & "/" & thename & "/\""
do shell script "mv \"" & posixfilepath & "\" \"" & "/" & posixfilepathSTRINGCLEANED & "/" & thename & "/\""
end if
end repeat
end open
on emptylist(klist)
set nlist to {}
set dataLength to length of klist
repeat with i from 1 to dataLength
if item i of klist is not "" then
set end of nlist to (item i of klist)
end if
end repeat
return nlist
end emptylist
on ListToString(theList, delim)
set oldelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set alist to theList as string
set AppleScript's text item delimiters to oldelim
return alist
end ListToString
on stringtolist(theString, delim)
set oldelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set dlist to (every text item of theString)
set AppleScript's text item delimiters to oldelim
return dlist
end stringtolist