![]() |
#1021 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,062
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: 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. |
![]() |
![]() |
![]() |
#1022 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 Code:
template = program: globals(do_continue) datatype = text comparison = "=" condition value = yes Last edited by capink; 02-18-2023 at 08:05 PM. |
![]() |
![]() |
![]() |
#1023 |
Enthusiast
![]() 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
Last edited by Dfaure; 02-22-2023 at 08:25 AM. Reason: broken title and completed questions |
![]() |
![]() |
![]() |
#1024 | ||||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
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:
Quote:
After defining this function in the module editor, you can call it from your template: Code:
program: device = friendly_connected_device_name('main') Quote:
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
Last edited by capink; 02-23-2023 at 01:36 PM. |
||||
![]() |
![]() |
![]() |
#1025 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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()] 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. |
|
![]() |
![]() |
![]() |
#1026 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Sounds good. I changed the name to current_column.
|
![]() |
![]() |
![]() |
#1027 | |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,062
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quote:
![]() 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. |
|
![]() |
![]() |
![]() |
#1028 |
Junior Member
![]() 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 ![]() |
![]() |
![]() |
![]() |
#1029 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,062
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. |
![]() |
![]() |
![]() |
#1030 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,062
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. |
![]() |
![]() |
![]() |
#1031 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,062
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 Last edited by ownedbycats; 03-03-2023 at 05:48 PM. |
![]() |
![]() |
![]() |
#1032 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
|
|
![]() |
![]() |
![]() |
#1033 | ||||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,200
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
Can't really comment much on that. Since you tried and noticed a speed improvement, it must be the reason of the delay. Quote:
Quote:
Quote:
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. |
||||
![]() |
![]() |
![]() |
#1034 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,062
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?
|
![]() |
![]() |
![]() |
#1035 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |