Hey gang, I am complete new to Applescript and I am looking for some help. Here is what I have:
Hi-res images labeled in this format: 123456.psd
What I would like to do:
Run a script that when called upon, places the files in the correct third level subfolder based on the first three digits of the file name. Here is a picture of the folder structure:
http://img138.imageshack.us/img138/5492/filestructuresj9.png
Can anyone help with this?
Thanks,
Jason
Model: MacBook Black
Browser: Firefox 3.0b3
Operating System: Mac OS X (10.5)
Hi Jason,
welcome to MacScripter.
Try this, it’s a droplet, this means, save it as application an drop the files on it.
If you double click it, you can choose the parent folder.
property baseFolder : missing value
on run
set baseFolder to choose folder
end run
on open theFiles
if baseFolder is missing value then set baseFolder to choose folder
repeat with oneFile in theFiles
tell text 1 thru 3 of name of (info for oneFile) to set destinationfolder to (baseFolder as text) & text 1 & ":" & text 1 thru 2 & ":" & text 1 thru 3 & ":"
tell application "Finder" to move oneFile to folder destinationfolder
end repeat
end open
My jaw is still left open right now. That is absolutely perfect. So, my next question is, can you point me in the direction to learn how to write the code for AppleScript? It all looks complicated, but I’m sure with some fundamentals, I could begin to understand it.
Thank you again.
Jason
It’s like learning a language.
For the basics read AppleScript for Absolute Starters (Free Download)
There are also helpful tutorials on ScriptWire (MacScripter start page)
Well, all was working great until I ran into duplicate file names. I’m really not a big fan of asking someone to just do this for me, but since I’m still in the very beginning stages of learning how to write the scripts myself, I don’t even know where to start.
Is there a way to add some sort of dialogue that if there is an existing file in the folder I’m moving files to, it asks me to rename the file?
Is this an easy fix? I’ve got a ton of files that I’m trying to transfer using this cool script, but without a renaming option, I’m stuck. Thanks again.
Jason
try this
property baseFolder : missing value
on run
set baseFolder to choose folder
end run
on open theFiles
if baseFolder is missing value then set baseFolder to choose folder
repeat with oneFile in theFiles
set fileName to name of (info for oneFile)
tell text 1 thru 3 of name of (info for oneFile) to set destinationfolder to (baseFolder as text) & text 1 & ":" & text 1 thru 2 & ":" & text 1 thru 3 & ":"
repeat
try
destinationfolder & fileName as alias
set fileName to text returned of (display dialog "file " & quote & (get fileName) & quote & " already exists." & return ¬
& "Please choose a different name" default answer (get fileName) buttons {"OK"} default button 1)
tell application "Finder" to set name of (contents of oneFile) to fileName
on error
tell application "Finder" to move oneFile to folder destinationfolder
exit repeat
end try
end repeat
end repeat
end open
Brilliant. I’m gonna learn this AppleScripting thing one day and return the favor. I promise.
Thanks again.
So, while this script works great for transferring my files, now I’m running into the problem where I only have a RENAME option once I’ve started transferring files. How would I go about adding a “Cancel” (to stop the script) and an “Overwrite” (to over write older files with the same name)?
Any help would be appreciated.