Automater/applescript help... Putting files in sub-folders with matching name
Hi,
I am new to automater and applescripts. Basically, I have a folder full of files of varying filetype (filecount is in the hundreds). I am trying to put every file in that folder into into its own subfolder that matches it's name (without the extension).
So ultimately I want the layout to go from:
Main Folder / Mountain.txt
Main Folder / Lion.avi
Main Folder / OSX.html
To...
Main Folder / Mountain / Mountain.txt
Main Folder / Lion / Lion.avi
Main Folder / OSX / OSX.html
So far I have been able to create a folder action that makes the subfolder when I add a file to the folder of my choice using something I found on stackoverflow (http://stackoverflow.com/questions/11220379/applescript-create-new-folder-from-f ile-name-and-move-file-into-that-folder)
on run {input, parameters} -- make new folders from base file names
set output to {}
repeat with anItem in the input -- step through each item in the input
set anItem to anItem as text
tell application "System Events" to tell disk item anItem
set theContainer to path of container
set {theName, theExtension} to {name, name extension}
end tell
if theExtension is in {missing value, ""} then
set theExtension to ""
else
set theExtension to "." & theExtension
end if
set theName to text 1 thru -((count theExtension) + 1) of theName -- the name part
tell application "Finder"
make new folder at folder theContainer with properties {name:theName}
set end of output to result as alias
end tell
end repeat
return input -- or output
end run
The problem is that this doesn't move the files into the newly created subfolders! So, I did a little more hunting last night and found the following:
on run {input, parameters} -- make new folders from base file names
set output to {}
repeat with anItem in the input -- step through each item in the input
set anItem to anItem as text
tell application "System Events" to tell disk item anItem
set theContainer to path of container
set {theName, theExtension} to {name, name extension}
end tell
if theExtension is in {missing value, ""} then
set theExtension to ""
else
set theExtension to "." & theExtension
end if
set theName to text 1 thru -((count theExtension) + 1) of theName -- the name part
tell application "Finder"
make new folder at folder theContainer with properties {name:theName}
set end of output to result as alias
end tell
end repeat
return input -- or output
end run
However, this doesn't seem to work! I've tried in automater making both a folder action and application and neither seems to work. I really am new to automater and didn't know if somebody could help me accomplish what I am trying to do.
Thank you so much!
-Joe
Mac mini, OS X Mountain Lion (10.8.2)