Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 02-18-2023, 05:11 PM   #1021
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Question:

There's a search modifier for "select books modified by last action." Can this be used as a conditional?

Example:

Click image for larger version

Name:	2023-02-18 18_05_28-Add actions.png
Views:	687
Size:	22.1 KB
ID:	199799

If I don't modify anything during action #1, can I then skip action #2? (Then also skip the third action by also testing whether the book was modiifed by action #2.)

Last edited by ownedbycats; 02-18-2023 at 05:26 PM.
ownedbycats is online now   Reply With Quote
Old 02-18-2023, 08:01 PM   #1022
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Right after the first action, insert a new "Chain Varibales" Action that defines a variable called do_continue with the following template:

Code:
program:
	start = format_date(globals(_previous_action_start_time), 'to_number');
	lm = format_date(last_modified(), 'to_number');
	if lm ># start then 'yes' else 'no' fi
After that set a condition on the last two actions as follows:

Code:
template = program: globals(do_continue)
datatype = text
comparison = "="
condition value = yes
Edit: The above assumes the first two actions are tied together. If there is a chance you are going to cancel first action but proceed with the second, you have to repeat the chain variables step after the second action.

Last edited by capink; 02-18-2023 at 08:05 PM.
capink is offline   Reply With Quote
Old 02-22-2023, 07:36 AM   #1023
Dfaure
Enthusiast
Dfaure began at the beginning.
 
Posts: 31
Karma: 10
Join Date: Jan 2013
Device: Kobo Libra 2 & Aura HD, Cybook Muse
Some issues with action chains and template language

Hi,

I'm used to managing several readers (mostly Kobos) from a single Calibre library instance. To keep track of which reader has transferred which book, I maintain an extra tag-like user column to store this data, and I wanted to automate the process using Action Chains.

So, I created a chain of one Single Field Edit action targeting my custom column, to be triggered manually as needed:

Code:
Choosen column: #extra_tags
Code:
program:
	tag_field = '#extra_tags';
	s = ',';
	fname = 'ondevice';
	device = connected_device_name('main');
	if field_exists(fname) then
		test(field(fname),
			list_union(field(tag_field), device, s),
			list_difference(field(tag_field), device, s))
	fi
This works globally, but I'm stuck on some annoyances or features that I miss in the plugin, the template language definition or even in Calibre itself:
  • Cf. the tag_field initialization, what is the way to get the name of the selected column in the template code without being forced to redefine it again in the template code?
  • When setting up the feature, I noticed that when dealing with Kobo readers, the device name reported was one of those I had specified via the Kobo Utilities plugin. I was wondering how I could get a similar customization for other device brands?
  • Given the previous consideration, what would be the best way to handle a bunch of associations between a <tag_text> and a <device_name> in my action chain, i.e. how could I use Chain Variables for that ?
Anyway, I also want to thank you for the quality of the tools and the environment they rely on.

Last edited by Dfaure; 02-22-2023 at 08:25 AM. Reason: broken title and completed questions
Dfaure is offline   Reply With Quote
Old 02-23-2023, 10:24 AM   #1024
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by Dfaure View Post
Cf. the tag_field initialization, what is the way to get the name of the selected column in the template code without being forced to redefine it again in the template code?
I defined a template function called current_column (see the code at the end of this post) that gets the selected column name, if @chaley has no interest in adding something similar to calibre, I will add it to the next version of Action Chains.

For now, you can define it as a custom template function in the module editor (see instructions below). After defining this function in the module editor, you can call it from your template:

Code:
program:
    col_name = current_column()
Quote:
Originally Posted by Dfaure View Post
When setting up the feature, I noticed that when dealing with Kobo readers, the device name reported was one of those I had specified via the Kobo Utilities plugin. I was wondering how I could get a similar customization for other device brands?
I don't use the Kobo Utilities plugin, so I am not sure what you are talking about here. Maybe someone else can help with this.

Quote:
Originally Posted by Dfaure View Post
Given the previous consideration, what would be the best way to handle a bunch of associations between a <tag_text> and a <device_name> in my action chain, i.e. how could I use Chain Variables for that ?
I am not sure what you want exactly. If you are talking about friendly names for your devices, there is a function defined below (friendly_connected_device_name) that helps you map the names. First, you need to edit the dictionary (highlighted in blue).

After defining this function in the module editor, you can call it from your template:

Code:
program:
    device = friendly_connected_device_name('main')
Quote:
Originally Posted by Dfaure View Post
Anyway, I also want to thank you for the quality of the tools and the environment they rely on.
Thanks.

To add the code below that contains both functions:
Action Chains > Manage Modules > Create Module > Copy/Paste the code below


Code:
import traceback
from calibre_plugins.action_chains.templates import TemplateFunction
from calibre.utils.formatter_functions import BuiltinConnectedDeviceName

class CurrentColumn(TemplateFunction):

    name = 'current_column'
    arg_count = 0

    def evaluate(self, formatter, kwargs, mi, locals):
        from calibre.gui2.ui import get_gui
        lv = get_gui().library_view
        col = lv.column_map[lv.currentIndex().column()]
        return col

class FriendlyConnctedDeviceName(TemplateFunction):

    name = 'friendly_connected_device_name'
    arg_count = 1

    def evaluate(self, formatter, kwargs, mi, locals, storage_location):
        from calibre.utils.formatter_functions import BuiltinConnectedDeviceName

        friendly_names = {
            'name_1': 'friendly_name_1',
            'name_2': 'friendly_name_2',
            'name_3': 'friendly_name_3'
        }

        try:
            name = BuiltinConnectedDeviceName.evaluate(self, formatter, kwargs, mi, locals, storage_location)
            return friendly_names.get(name, name)
        except:
            traceback.print_exc()
            raise
Edit: Defining the function as pointed out by chaley in the next post, gives you the advantage of being able to use it outside Action Chains as well.

Last edited by capink; 02-23-2023 at 01:36 PM.
capink is offline   Reply With Quote
Old 02-23-2023, 10:51 AM   #1025
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by capink View Post
I defined a template function called selected_column (see the code at the end of this post) that gets the selected column name, if @chaley has no interest in adding something similar to calibre, I will add it to the next version of Action Chains.
Given that it will be rarely used and is easy to implement as a fast python stored template, I don't think adding it to base calibre is required. Action Chains users can use what you add. People who want the function can create a stored template.

You might consider whether using a stored template is a good solution for you. A stored template will work just as well, and you aren't required to maintain it.

The stored template code is (like yours):
Code:
python:
def evaluate(book, context):
	from calibre.gui2.ui import get_gui
	gui = get_gui()
	cv = get_gui().current_view()
	return cv.column_map[cv.currentIndex().column()]
Assuming the name is (like yours) "current_column" the "adding" dialog Preferences / Template functions is
Click image for larger version

Name:	Clipboard03.jpg
Views:	666
Size:	95.0 KB
ID:	199877

I slightly prefer the name "current_column", but I think it is more important that we use the same name.

Last edited by chaley; 02-23-2023 at 11:06 AM.
chaley is offline   Reply With Quote
Old 02-23-2023, 11:03 AM   #1026
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Sounds good. I changed the name to current_column.
capink is offline   Reply With Quote
Old 02-23-2023, 03:04 PM   #1027
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by capink View Post
Right after the first action, insert a new "Chain Varibales" Action that defines a variable called do_continue with the following template:

Code:
program:
	start = format_date(globals(_previous_action_start_time), 'to_number');
	lm = format_date(last_modified(), 'to_number');
	if lm ># start then 'yes' else 'no' fi
After that set a condition on the last two actions as follows:

Code:
template = program: globals(do_continue)
datatype = text
comparison = "="
condition value = yes
Edit: The above assumes the first two actions are tied together. If there is a chance you are going to cancel first action but proceed with the second, you have to repeat the chain variables step after the second action.
This works, thanks.

I have "add purchase information" as a chain, but also use chain caller to run it as part of my general cleanup chain. However, not all books need purchase information (public domain, game manuals, etc), or sometimes I run it after adding the info so skipping the last two steps saves a bit of time.

Last edited by ownedbycats; 02-23-2023 at 03:16 PM.
ownedbycats is online now   Reply With Quote
Old 03-02-2023, 09:53 AM   #1028
sonicyouth
Junior Member
sonicyouth began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Mar 2023
Device: Kindle Oasis
ModifyEpub and Action Chains

Hi folks - wondered if you could help me out. I'm trying to set up an action chain such that text encoding will be changed to UTF-8 (using the ModifyEpub plugin) whenever an epub is added to my library. So far I have:

- Added the "Books Added" event to action chains
- Set up a chain which is triggered by this which then uses a Calibre Actions action specifying the ModifyEpub menu item

Where struggle is that the above action opens up the relevant pane for the ModifyEpub plugin, but I need to automate clicking "OK" on that pane - any advice on how this might be achieved?

Any help much appreciated !
sonicyouth is offline   Reply With Quote
Old 03-03-2023, 02:25 AM   #1029
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Would a program: connected_device_name('main') conditional on the last action cause anoticeable delay at the beginning of a chain? Removing it seems to have sped it up but it's difficult to measure for sure.

Additional question: The action in question is Reading List "sync now." The action greys out in the Reading List menu when no device is connected. Do you know if this means I can probably remove the condition?

Thanks.

Last edited by ownedbycats; 03-03-2023 at 02:38 AM.
ownedbycats is online now   Reply With Quote
Old 03-03-2023, 03:02 AM   #1030
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Bug?

In the Chain Variables action, the checkboxes for iterate and runtime don't seem to work. On an existing one I can uncheck runtime but not re-check it.

EDIT: Exiting Calibre and ediitng the json file to modify it to true works, but isn't ideal.

Last edited by ownedbycats; 03-03-2023 at 03:08 AM.
ownedbycats is online now   Reply With Quote
Old 03-03-2023, 05:46 PM   #1031
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Enhancement Request, if feasible:

In the conditional dialog, the option to add a custom failure message rather than this:

Code:
calibre, version 6.13.0
ERROR: Cannot run chain: Action Chains: conditions for chain (Read) are not met
This specific chain uses a selection_count() check so I would put something like "Only run this chain on a single book."

Last edited by ownedbycats; 03-03-2023 at 05:48 PM.
ownedbycats is online now   Reply With Quote
Old 03-05-2023, 02:20 AM   #1032
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by sonicyouth View Post
Hi folks - wondered if you could help me out. I'm trying to set up an action chain such that text encoding will be changed to UTF-8 (using the ModifyEpub plugin) whenever an epub is added to my library. So far I have:

- Added the "Books Added" event to action chains
- Set up a chain which is triggered by this which then uses a Calibre Actions action specifying the ModifyEpub menu item

Where struggle is that the above action opens up the relevant pane for the ModifyEpub plugin, but I need to automate clicking "OK" on that pane - any advice on how this might be achieved?

Any help much appreciated !
There is no way around this. Calibre Actions is intended for non-interactive actions.
capink is offline   Reply With Quote
Old 03-05-2023, 02:26 AM   #1033
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
Would a program: connected_device_name('main') conditional on the last action cause anoticeable delay at the beginning of a chain? Removing it seems to have sped it up but it's difficult to measure for sure.

Can't really comment much on that. Since you tried and noticed a speed improvement, it must be the reason of the delay.


Quote:
Originally Posted by ownedbycats View Post
Additional question: The action in question is Reading List "sync now." The action greys out in the Reading List menu when no device is connected. Do you know if this means I can probably remove the condition?

Thanks.
Don't thinks so. Give it a try and see for yourself.


Quote:
Originally Posted by ownedbycats View Post
Bug?

In the Chain Variables action, the checkboxes for iterate and runtime don't seem to work. On an existing one I can uncheck runtime but not re-check it.

EDIT: Exiting Calibre and ediitng the json file to modify it to true works, but isn't ideal.
I cannot replicate this. It works normally for me.


Quote:
Originally Posted by ownedbycats View Post
Enhancement Request, if feasible:

In the conditional dialog, the option to add a custom failure message rather than this:

Code:
calibre, version 6.13.0
ERROR: Cannot run chain: Action Chains: conditions for chain (Read) are not met
This specific chain uses a selection_count() check so I would put something like "Only run this chain on a single book."

The condition dialog is crowded enough as it is. The best I can do is to inlucde the condition's toolitp in the error message. Will add this to the next version.
capink is offline   Reply With Quote
Old 03-05-2023, 06:20 AM   #1034
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I install Action Chains in a clean portable instance of Calibre 6.13 and the iterate/runtime checkboxes aren't working. I think you use Linux, so could it be a Windows specific issue?
ownedbycats is online now   Reply With Quote
Old 03-05-2023, 07:36 AM   #1035
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,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
My bad. I was testing on an older version of calibre. A new version with the fix is now in the first post.
capink is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Action Chains Resources capink Plugins 78 08-05-2025 04:01 AM
[Editor Plugin] Editor Chains capink Plugins 106 06-17-2025 05:36 PM
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB lrpirlet Plugins 2 08-18-2022 03:15 PM
[GUI Plugin] Save Virtual Libraries To Column (GUI) chaley Plugins 14 04-04-2021 05:25 AM


All times are GMT -4. The time now is 07:04 PM.


MobileRead.com is a privately owned, operated and funded community.