View Single Post
Old 09-18-2020, 07:25 AM   #353
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,201
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
Is there any option in Open With to open the book path with an external program?
If you mean by that you want to open the parent folder with a file manager other than the default one, you have two possible solutions:
  • Write a script (shell or python) that gets the dir path from the file path, and then opens the directory with your preferred program. In the plugin config window, add the path to this script to the Application path field.
  • Use the template function added by davidfor in the plugin. It allows you to define a template, and pass its output in place of the book path to whatever external program you want. Here is an example of a template that gets the parent directory path:

    Code:
    program: paths = formats_paths();
    fmt_path = re(paths, ',[A-Z0-9_]+:.*', '');
    path = list_item(fmt_path, 1, ':');
    dir_path = re(path, '(.+)[/\\].*', '\1')
    This is the best I can come up with. Maybe someone can come up with a simpler template.

Note that both approaches will not work for books with no formats. You must have at least one format.

The template approach has another problem, because the plugin passes an extra empty string, which will make your file manager open another instance (pointing to you home directory). I think this is a bug in the template feature.


@davidfor: As I understand, the purpose of the template feature is to pass the template output in place of the file path. If so, I think lines 178,179 in the file action.py should be modified to prevent the behavior described above:

from:

Code:
            app_args = SafeFormat().safe_format(app_args, mi, 'Open With template error', mi)
            self.launch_app(external_app_path, app_args, '', wrap_args=False)
to:

Code:
            path_to_file = SafeFormat().safe_format(app_args, mi, 'Open With template error', mi)
            self.launch_app(external_app_path, '', path_to_file, wrap_args=False)
capink is offline   Reply With Quote