How do I use the current folder name without a path as a variable in automator in Mac?

倖福魔咒の 提交于 2019-12-03 12:30:51
markhunte

This works in testing:

  1. Ask for finder Items - set type to Folders.
  2. Set Value of Variable - this will be the path to the folder taken from action 1.
  3. Run Shell Script - set the Pass input : as argument. And use /usr/bin/basename "$1" as the command line to get the folder name
  4. Set Value of Variable - this will be the folderName of the folder taken from action 3.
  5. 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

  6. Get Folder Contents - get the contents of the folder at the path passed on from Action 5

  7. Rename Finder Items - Set to Make Sequential and new name = the folderName Variable

You can add your Move actions after as you wish.

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.

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:

  1. Ask for finder Items - set type to Folders.
  2. Set Value of Variable - this will be the path to the folder taken from action 1.
  3. Run Shell Script - set the Pass input : as argument. And use echo ${1##*/} as the command line to get the folder name
  4. Set Value of Variable - this will be the folderName of the folder taken from action 3.
  5. 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
  6. Get Folder Contents - get the contents of the folder at the path passed on from Action 5
  7. New PDF Contact Sheet - To make a PDF of a Contact sheet from passed folder
  8. Rename Finder Items - Set to Name Single Item and Name: set to Basename Only with folderName Variable
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!