Saturday, November 27, 2021
  • Index
  •  » Automator
  •  » Create subfolder in selected folder not current directory

#1 2021-10-01 12:30:02 pm

jprokos
Member
Registered: 2019-09-02
Posts: 6

Create subfolder in selected folder not current directory

I want to make a new folder in the currently selected folder instead of the current directory using an automator Quick Action.

I have tried this but I am failing at the very beginning because for some reason "Get Value of Variable - Path" is giving me two paths instead of just the one that is selected in Finder. The second path is always ~/Desktop.


My idea was to get the path of the currently selected folder and then use that to run a shell script that uses that path with a "mkdir /Untitled Folder" command.

New Folder Here.workflow

Model: iMac
Browser: Safari 605.1.15
Operating System: macOS 10.14

Last edited by jprokos (2021-10-01 02:47:47 pm)

Offline

 

#2 2021-10-01 03:17:09 pm

jprokos
Member
Registered: 2019-09-02
Posts: 6

Re: Create subfolder in selected folder not current directory

I got it.

New Folder Here

Last edited by jprokos (2021-10-01 03:26:23 pm)

Offline

 

#3 2021-10-04 06:27:04 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 150

Re: Create subfolder in selected folder not current directory

I can't recall the exact details (and it's always awkward testing other people's services) but I think that two sets of data are being passed to the last action. In an earlier action, see if there is an 'ignore input' checkbox that you can check and try again.

I'll try and mimic this as best I can but I have an older OS so it might not be exactly the same.


Filed under: Automator, input

Offline

 

#4 2021-10-04 06:50:00 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 150

Re: Create subfolder in selected folder not current directory

Alternatively, how about letting automator make the new folder with its native actions?

Leave your 'service' setting as is but use these two actions instead:

Set Value of Variable
    Variable: Storage

New Folder
    Name: Entitled folder
    Where: Storage
    
    For the last action do these two things…
        Drag the 'Storage' variable onto the 'where' dropdown to set it
        Check the 'Ignore this action's input' option

The first action takes the selected folder and assigns its path to the variable 'Storage'.

The second action creates the new folder in that location. If you do not check 'ignore', then it will create folders recursively, which nobody wants.

Offline

 

#5 2021-10-05 10:37:47 am

jprokos
Member
Registered: 2019-09-02
Posts: 6

Re: Create subfolder in selected folder not current directory

That works too. Not sure which is faster or better but I like learning. For me the method I used is clear to read and decipher whereas yours is not, but I can never understand how Automator variables work and avoid them... like a black hole.

I also don't understand why "ignore this action's input" doesn't ignore "Set Value of Variable" the first time.

Offline

 

#6 2021-10-05 05:47:31 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 150

Re: Create subfolder in selected folder not current directory

I share those frustrations with figuring out how automator works under the hood, and for years and years I too avoided using variables. A while ago I managed to do something using one so now I'll use them occasionally. Part of the problem for me is that I always feel uncomfortable with 'run applescript/shell' in automator when I can't know exactly what file references are being passed on. I really wish that Apple had made an easy method of showing the user what the inputs and outputs are. What helped me is that I managed to get a 'run applescript' action throw up a dialogue displaying what the input was and how it basically stuck two unrelated file references into a single output and how that changed when I checked ignore.

How automator seems to work is that each action automatically passes whatever it did on to the next (unless you 'ignore'). And visually, you can see that with the connection between actions, which disappear when you check ignore. So I think of it as there being both explicit (Storage variable) and implicit (current folder) references being passed on. Ignore stops the implicit one. As an aside, Apple did a poor job with this in the 'dark' version. In the normal display, there is a directional aspect to the connection.

So by checking ignore in my workflow, nothing is automatically passed between the 'set value' and 'new folder' actions. Instead, it only reads Storage, whose value it puts in the 'where' field. If you didn't check ignore, then it would do something weird… it would take both the current folder and the new folder and recursively re-create pairs of folders. I get 20 of each when I run it and then it stops itself (thankfully). Weirder, it actually duplicates the current folder (including its other contents) so as my test folder also contains a word doc, that file was also duplicated 20 times.


Filed under: Automator, variable

Offline

 
  • Index
  •  » Automator
  •  » Create subfolder in selected folder not current directory

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)