You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

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

How can I apply the name of the folder before the files name within that folder?

So I have a list of folders which are all my clients. Within each folder I have documentation of each clients. The documentations file names are the same for each client, so for example:


Service order

Packing list

Shipping documents

etc...


These files are for example in the folder called "NAME LAST NAME". How can I have a script that automatically sets all files within that folder as:


NAME LAST NAME Service order

NAME LAST NAME Packing List

NAME LAST NAME Shipping documents

NAME LAST NAME etc...


Thank you!

Posted on Nov 13, 2020 1:43 AM

Reply
Question marked as Top-ranking reply

Posted on Nov 13, 2020 2:27 AM

It might be as simple as this AppleScript which prompts you for the folder, and then prepends the folder name to each item in that folder.


  1. Open Script Editor, and copy/paste the following code into it.
  2. Click the Compile button, and then click the Run button.
  3. Save the AppleScript as text and give it a useful name (e.g. prepend.applescript).


use scripting additions

set folder_name to (choose folder default location (path to desktop))

tell application "Finder"
	set the folder_list to (every item in folder folder_name) as alias list
	if folder_list = {} then return
	
	repeat with afile in folder_list
		set afile's name to (folder_name's name as text) & space & afile's name
	end repeat
end tell
return



Similar questions

5 replies
Question marked as Top-ranking reply

Nov 13, 2020 2:27 AM in response to Speida

It might be as simple as this AppleScript which prompts you for the folder, and then prepends the folder name to each item in that folder.


  1. Open Script Editor, and copy/paste the following code into it.
  2. Click the Compile button, and then click the Run button.
  3. Save the AppleScript as text and give it a useful name (e.g. prepend.applescript).


use scripting additions

set folder_name to (choose folder default location (path to desktop))

tell application "Finder"
	set the folder_list to (every item in folder folder_name) as alias list
	if folder_list = {} then return
	
	repeat with afile in folder_list
		set afile's name to (folder_name's name as text) & space & afile's name
	end repeat
end tell
return



Nov 13, 2020 3:21 AM in response to Speida

Yes, by way of an Automator Quick Action (service) where you right-click on a folder, and choose Quick Action ▸ Quick Action name. For example, I have right-clicked on a folder named Jon Jones:


I gave the Quick Action an arbitrary name, and you certainly can make it shorter if you wish.


  1. Launch Automator
    1. New Document. Quick Action. Choose.
  2. Set the top part of the Quick Action panel to the following:
  3. From the Library : Utilities, drag and drop the Run AppleScript action onto the right-hand workflow window
  4. Open a new line above the on run handler to include use scripting additions
  5. Replace this line (* Your script goes here *) with the following code


set folder_name to (input as text) as alias
	
	tell application "Finder"
		set the folder_list to (every item of folder folder_name) as alias list
		if folder_list = {} then return
		repeat with afile in folder_list
			set afile's name to (folder_name's name) & space & afile's name
		end repeat
	end tell


Click the compile (hammer) icon in the Run AppleScript Action, and then save the Quick Action with your own unique name for it. Quit Automator, right-click on your target folder, and use the first image menu structure to apply your Quick Action. The Automator Quick Action should look like the following when done:





This was tested on Mojave 10.14.6 (18G6042).

How can I apply the name of the folder before the files name within that folder?

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