Hi Everyone - This seems like a great forum and resource. I am a newbie at Applescripting, but can see how powerful it is. I am hoping to get a little help with creating a script of my own. Hopefully I can be of help once I learn more!
I’d like to rename a file to the name of its nearest parent directory. So if I have:
-Incoming
–Folder1
—File.m4v
I’d like the name to be Folder1.jpg.
I’ve seen some good scripts that deal with ideas like this, but nothing that nails it on the head. The one thing I’d like to add as an if/then/else statement because some of the files do not have a parent folder and thus their parent folder is “Incoming” as seen above. And I’d rather not get a lot of files named “Incoming”.
So IF the parent folder of file.jpg is NOT “Incoming”, THEN rename it to its parent folder. ELSE ignore.
set theFile to choose file
tell application "Finder"
set parentFolderName to name of container of theFile
if parentFolderName is not "Incoming" then
set fileExtension to name extension of theFile
set name of theFile to parentFolderName & "." & fileExtension
end if
end tell
Thanks for the reply Stefan! I am trying to run this script inside of a program called Hazel. When I run the script I get the following error. I don’t know if I should go to the Hazel forums for this or if there is something you could help with. Thanks again for any help!