View Single Post
Old 01-10-2024, 02:32 AM   #1216
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,203
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by nqk View Post
I want to extract a certain file from the txtz file to certain folder. I create this cmd file with only one line, and it works (drag and drop or open-with in Windows Exlorer)

Code:
"C:\Program Files\7-Zip\7z.exe" e %1 -o"D:\Temp" file-to-extract -y
However, the "Open with" action in this Plugin (with binarypath being the path to the cmd file) doesn't do anything.

Please help me to config the ActionChain to make it work.

At present, my work around is
1) In Windows, set the cmd file as "default app" to open txtz file (which I don't really like)
2) In Acction Chain, use "Open with default app".

This is not a good solution, I think.
I will be limited in how much I can help you with this, because I'm not on Windows.

My suggestion for you is to save the above command as a batch file (I suppose that is what you mean by cmd file), and add the path to the batch file using the "choose binary" button. This way you don't need to set the cmd file as the default app.

Edit: If the above solution fails (maybe batch files cannot be executed the same way bash files are in linux), you can use the following code in "Run Python Code Action"

Code:
import subprocess

def run(gui, settings, chain):
    db = gui.current_db
    output_dir = 'D:\Temp'
    for book_id in chain.scope().get_book_ids():
        path_to_txtz = db.format_abspath(book_id, 'TXTZ', index_is_id=True)
        title = db.title(book_id, index_is_id=True)
        if not path_to_txtz:
            print(f'Book {title} does not have format: TXTZ')
            continue
        cmd = f'"C:\Program Files\7-Zip\7z.exe" e {path_to_txtz} -o"{output_dir}" file-to-extract -y'
        result = subprocess.run(cmd)
        if result.returncode != 0:
            prints(f'Command error: Return code is {result.returncode} when running command for file: {path_to_txtz}\ncmd: {cmd}')
            sys.stdout.buffer.write(b'stderr: ' + result.stderr)
            prints()

Last edited by capink; 01-10-2024 at 02:47 AM.
capink is offline   Reply With Quote