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

3

14

I am using Mac OSX 10.8.3.

I have a workflow in Automator set up that is as follows:

  1. Ask for Finder Items
  2. Get Folder Contents
  3. Make Sequential
  4. 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 screen shot

Contumacy answered 5/4, 2013 at 10:45 Comment(2)
I think you will have more luck with your question on apple.stackexchange.comBibliophile
Where/how are you picking this new folder fromWeil
W
17

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

enter image description here

You can add your Move actions after as you wish.

Weil answered 16/7, 2013 at 10:29 Comment(0)
H
5

You can use a Run Shell Script Action, with the following code:

echo ${1##*/}

and Pass input: set to as arguments.

enter image description here

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.

Hutchinson answered 5/4, 2013 at 12:32 Comment(0)
C
1

another short version to get a folder name and assign it to a variable.

tell application "Finder"
    set currentDir to target of Finder window 1 as alias
    set posixDir to POSIX path of currentDir
    -- set myShell to "touch \"" & posix & "\"readme.txt"
    -- set result to (do shell script myShell)
end tell

screenshot

Cecum answered 2/1, 2022 at 7:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.