creating directories and moving files

Hi everyone, i’m new to scripting and have 2 questions:

I am in need of a script that looks in a directory of files, pulls the names from the JPEG then moves the similar images into the corresponding directory.The closest I could find was a script that, once the JPEGs are selected creates folders from the JPEGS, then it moves the JPEG into the corresponding directory. here is the script I have:

tell application "Finder"
	set current_folder to folder of front window
	set x to (get the selection) as list
	repeat with i from 1 to the count of x
		set this_file to item i of x
		if i is not 1 then
			set previous_file to item (i - 1) of x
			set prev_ext to cur_ext
			set prev_name to new_name
			set prev_name to ""
		end if
		set cur_ext to name extension of this_file
		set new_name to text 1 thru -((length of cur_ext) + 2) of (name of this_file as text)
		if new_name is not equal to prev_name then
			set new_folder to make new folder with properties {name:new_name} at current_folder
			move this_file to new_folder
			move this_file to new_folder
		end if
	end repeat
end tell

here is what the directory looks like now:

and here is what my desired end result would look like:

13875980Medium (directory containing all similar files with “.psd" in name)
14507383Medium (directory containing all similar files with "
.psd” in name)
14649968Medium (directory containing all similar files with “.psd" in name)
14905715Medium (directory containing all similar files with "
.psd” in name)
16133522Medium (directory containing all similar files with “_.psd” in name)

and this leads me to the second part of my question, can I get some opinions on the best begining guide to applescripting that’s not too elemnetary, unless you all think I need that :wink:

I have some background in HTML writing and a basic understanding of applescripting. My main focus would be workflow automation involving and combining the OS, Photoshop and excel.

sorry is this post is too lengthy, it’s my first post and I want ot make sure it’s detailed.

thanks anyone for help, I truly appreciate it.



taking the result from “what my desired end result would look like” (move all psd files into the appropriate directories and leave the jpg), try this.
you will be prompted to choose the directory

set baseFolder to choose folder
set baseFolderPOSIX to POSIX path of baseFolder
tell application "Finder" to set fileList to files of baseFolder
repeat with aFile in fileList
	tell aFile to set {nameExtension, fileName, filePath} to {name extension, name, it as text}
	if nameExtension is "psd" then
		set o to offset of "Medium" in fileName
		set prefix to text 1 thru (o + 5) of fileName
		set destinationFolder to baseFolderPOSIX & prefix
		do shell script "/bin/mkdir -p " & quoted form of destinationFolder
		do shell script "/bin/mv " & quoted form of POSIX path of filePath & space & quoted form of (destinationFolder & "/" & fileName)
	end if
end repeat

OH MAN, THANKS STEFAN!!! your script looks so much cleaner than anything i’ve seen so far and non of the other stuff got me to where I needed to be but yours does! I can’t thank you enough for the help, it’s perfect!!!

I just noticed you have a shell script running inside, very cool



mkdir and mv shellscripts are the only way to fly when you’re moving lots of files around.
The Finder can become abysmally slow, even unresponsive, if you make a couple hundred calls to have it move single files within a loop. Shell scripts bypass that bottleneck.