Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Folder with Selection (script) #1103

Open
dmt-hub opened this issue Dec 22, 2024 · 1 comment
Open

New Folder with Selection (script) #1103

dmt-hub opened this issue Dec 22, 2024 · 1 comment

Comments

@dmt-hub
Copy link

dmt-hub commented Dec 22, 2024

I have this script (provided by ChatGPT) to place selected files in a folder with a shortcut.
Thing is: it puts the selected files in a new folder - but doesnt let me name the folder.

Maybe someone with the right skills can help out?

Here’s a script for Marta that lets you create a new folder and move selected files into it. You can configure it to be triggered with a shortcut (e.g., Option+Cmd+F). Here's how to set it up:


1. Python Script: move_to_new_folder.py

import sys
import os
import shutil

def move_to_new_folder(selection_paths, destination_dir):
    os.makedirs(destination_dir, exist_ok=True)

    for path in selection_paths:
        if os.path.exists(path):
            new_path = os.path.join(destination_dir, os.path.basename(path))
            shutil.move(path, new_path)
            print(f"Moved {path} to {new_path}")
        else:
            print(f"Error: {path} does not exist.")

if __name__ == "__main__":
    if len(sys.argv) > 2:
        destination_folder = sys.argv[1]
        file_paths = sys.argv[2:]
        move_to_new_folder(file_paths, destination_folder)
    else:
        print("Usage: python move_to_new_folder.py <destination_folder> <file_paths...>")

Save this script, for example, in /path/to/marta/scripts/move_to_new_folder.py.


2. Marta Configuration

Add a New Gadget

Edit your config.marta file to include a gadget for the new functionality:

gadgets [
    {
        id "gadget.action.move_to_new_folder"
        name "Move to New Folder"
        type "executable"
        executable "/usr/local/bin/python3"
        args [
            "/path/to/marta/scripts/move_to_new_folder.py"
            "${prompt.text 'Enter new folder name:'}"
            "${active.selection.paths}"
        ]
        workingDirectory "${active.folder.path}"
    }
]

Replace /path/to/marta/scripts/ with the actual path to your script.


Keybinding

Assign the functionality to the Option+Cmd+F shortcut:

keyBindings {
    "Option+Cmd+F" "gadget.action.move_to_new_folder"
}

3. Usage

  1. Select the files you want to move in Marta.
  2. Press Option+Cmd+F.
  3. Marta will prompt you to enter the name of the new folder.
  4. Enter the folder name, and the files will be moved into the newly created folder.

This script works by prompting the user for the folder name and moving selected files into the new folder within the current directory. The gadgets and keyBindings ensure seamless integration with Marta.

@dmt-hub dmt-hub changed the title New Folder with Selection (gadget script) New Folder with Selection (script) Dec 22, 2024
@Skugg4n
Copy link

Skugg4n commented Jan 2, 2025

Hey! I gave this a try and explored several different ideas. However, as far as I can tell, Marta doesn’t currently support prompting for user input directly through a script. I eventually devised a workaround using Keyboard Maestro alongside a Marta script. It works for me, but it does require KM, and I think it’s always preferable to avoid juggling multiple systems for small functions.

Anyway, here’s my ugly workaround:
Essentially, I trigger a KM macro from Marta that prompts for user input to name the new folder. KM stores the name in a variable, then triggers a Marta macro to create a new folder and move the selected files into it. Finally, KM looks up the new folder and renames it using the stored variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants