问题
I am using Mac OSX 10.8.3.
I have a workflow in Automator set up that is as follows:
- Ask for Finder Items
- Get Folder Contents
- Make Sequential
- Move Finder Items
The purpose of the workflow is to automate renaming a bunch of photos that I have saved in folders then move them to an new folder.
I want to grab the foldername and stick it in a variable and use that variable in the "new name box" in the Make Sequential section of the work flow (see attached) image.
How do I grab just the folder name and assign it to a variable. My example has a variable called "FolderName"
Here is a screenshot
回答1:
This works in testing:
- Ask for finder Items - set type to Folders.
- Set Value of Variable - this will be the path to the folder taken from action 1.
- Run Shell Script - set the Pass input : as argument. And use /usr/bin/basename "$1" as the command line to get the folder name
- Set Value of Variable - this will be the folderName of the folder taken from action 3.
Get Value of Variable - set the Variable it obtains the value of to path
5a. set action 5 to ignore input from the above action 4 - Ctrl + mouse click on the action Title to get the Contextual Menu
Get Folder Contents - get the contents of the folder at the path passed on from Action 5
- Rename Finder Items - Set to Make Sequential and new name = the folderName Variable
You can add your Move actions after as you wish.
回答2:
You can use a Run Shell Script Action
, with the following code:
echo ${1##*/}
and Pass input:
set to as arguments
.
This will filter the passed input, giving only the file basename as output.
You should put this step before the action that sets FolderName
variable.
回答3:
I'm trying to do a similar thing but instead of rename individual files, I want to create a pdf with the files and rename that pdf with the folder name as the name for the pdf file. This is what I have but can't get it to work:
- Ask for finder Items - set type to Folders.
- Set Value of Variable - this will be the path to the folder taken from action 1.
- Run Shell Script - set the Pass input : as argument. And use echo ${1##*/} as the command line to get the folder name
- Set Value of Variable - this will be the folderName of the folder taken from action 3.
- Get Value of Variable - set the Variable it obtains the value of to path. set action 5 to ignore input from the above action 4
- Get Folder Contents - get the contents of the folder at the path passed on from Action 5
- New PDF Contact Sheet - To make a PDF of a Contact sheet from passed folder
- Rename Finder Items - Set to Name Single Item and Name: set to Basename Only with folderName Variable
来源:https://stackoverflow.com/questions/15831913/how-do-i-use-the-current-folder-name-without-a-path-as-a-variable-in-automator-i