organize icon indicating copy to clipboard operation
organize copied to clipboard

Passing arguments in Automator

Open iburunat opened this issue 4 years ago • 4 comments

The idea here is to to apply a rule to a folder of choice by right-clicking the folder (or selecting the files and right-clicking) and choosing the organize action (which would include a specific --config-file=<>).

So the question is how to pass the specified folder or files arguments onto organize? Is there a way we can specify this in the config file? This would prove really useful to organize certain folders on the spot.

Thanks in advance!

iburunat avatar Jun 17 '20 05:06 iburunat

That's an interesting use-case! I haven't worked with Automator much so far but it should be possible to define environment variables? If this is the case then you should be already able to use environment variables as folders:

rules:
  - folders: $MY_FOLDER
    actions:
      - echo: "{path}"

And call it with MY_FOLDER="~/Desktop" organize sim

tfeldmann avatar Jun 22 '20 11:06 tfeldmann

Thanks, @tfeldmann! I have been trying this approach with automator but I'm failing to pass the arguments to organize. Probably a minor coding issue. Will let you all know when I manage to make it work as it would be very useful :)

iburunat avatar Jul 02 '20 04:07 iburunat

Any updates on this?

tfeldmann avatar Nov 10 '20 15:11 tfeldmann

Hi there! And thanks for asking.

Unfortunately, I haven't managed to make it work (even after last upgrade).

As I mentioned above, the idea is to create an Automator shell script that then I can call from any folder with a mouse click or key shortcut. The Automator shell script receives current "files or folders" and passes input "as arguments". It contains the following:

export PATH=/usr/local/bin:$PATH
MY_FOLDER="$@" 
organize --config-file=/path/to/config.yaml run

The YAML config file defines folder as this:

- folders: $MY_FOLDER

However, when I call this from a folder, nothing happens (it is supposed to sort file types into subfolders).

iburunat avatar Nov 12 '20 07:11 iburunat

Got it working!

Bildschirmfoto 2022-08-12 um 18 56 10

Automator shell script:

export PATH=/usr/local/bin:~/.local/bin:$PATH
MY_FOLDER="$@"
organize run ~/Dropbox/Apps/organize/finder-action.yml --working-dir="$MY_FOLDER" > $MY_FOLDER/organize.txt

This uses the new working-dir argument. In your config you then use . as location, no need for env variables:

rules:
  - locations: "."
    filters:
      - name: "test-trash-this-file"
    actions:
      - trash

In the organized folder you will find a organize.txt for debugging. You can disable this in the shell script. The automator action:

organize this folder.zip

EDIT: Make sure your config file is not on the desktop, I got permission errors there. Putting it into dropbox works fine for me.

tfeldmann avatar Aug 12 '22 16:08 tfeldmann

Hey! Just wanted to drop a quick note to say thanks for your response to this issue. It's been a busy time on my front but finally got around to trying your solution, and it worked like a charm!

iburunat avatar Jul 24 '23 17:07 iburunat