Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript Help - Add folder name to contents

Hi everyone


I am an Applescript newbie, and I need help!


I have a several folders with 2 jpegs inside them.

All the jpegs are titled "image1.jpg" & "image2.jpg"


I am looking for a quick way to add the folder name as a prefix to each jpeg.


Example:


Folder name - Wellington Boots

Images inside - image1.jpg


The outcome I am looking for is:


Folder name - Wellington Boots

Images inside - Wellington Boots-image1.jpg


This might be really easy to do, but I am struggling to find info on how to do it. Can anyone help?

APPLESCRIPT-OTHER

Posted on Apr 25, 2013 7:43 AM

Reply
Question marked as Best reply

Posted on Apr 25, 2013 8:37 AM

Something like the following should do it:


settheinputto (choose filewithmultiple selections allowed)

tellapplication"Finder"


repeatwithanItemintheinput

setprefixtonameofcontainerofanItem

setnameofanItemtoprefix & "-" & nameofanItem


endrepeat

endtell

You can also paste just the Finder tell block into an Automator Run AppleScript action to use it in a service workflow.

4 replies
Question marked as Best reply

Apr 25, 2013 8:37 AM in response to bcam71

Something like the following should do it:


settheinputto (choose filewithmultiple selections allowed)

tellapplication"Finder"


repeatwithanItemintheinput

setprefixtonameofcontainerofanItem

setnameofanItemtoprefix & "-" & nameofanItem


endrepeat

endtell

You can also paste just the Finder tell block into an Automator Run AppleScript action to use it in a service workflow.

Apr 25, 2013 9:18 AM in response to red_menace

Actually, to make it a bit more robust you can change the script to


tellapplication"Finder"


repeatwithanItemintheinput

set prefix to (name of container of anItem) & "-"

settheNametonameofanItem

iftheNamedoes notstart withprefixthen-- already prefixed

setnameofanItemtoprefix & theName

endif


endrepeat

endtell


That way it won't add a prefix if there already is one.

Applescript Help - Add folder name to contents

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.