Say I want to make all my “reserarch” notes private.
Is there any way I can do it other than editing them one by one?
Say I want to make all my “reserarch” notes private.
Is there any way I can do it other than editing them one by one?
Set up a Custom Filter that finds all the “Research” notes.
If it was a Person, Event, or Media; then you could have used the Set Privacy addon tool (Tools → Family Tree Processing → Set Privacy… ) with that filter.
You might ask @Mattkmmr if he would expand his Set Privacy tool to handle Notes too. When someone had a similar inquiry about setting Event privacy en masse, he knocked out a very quick and powerful enhancement to his Set Privacy tool.
Thanks for the info and the links. I’m not a technical user, so unfortunately writing a script is not an option for me.
I have a small DB, It doesn’t take much time to change manually all my notes, so is not really a problem in my case. I simply assumed that this kind of batch editing was possible with the core program but I was unable to find a way to do it.
Having said that, it would be nice if the Set Privacy Tool would support notes too.
The script was REALLY easy to adapt.
Here, I’ve gone into the Notes category and created a Custom Filter for “Source Note” type Notes.
(Using the Example.gramps tree, this filtered to 2 of that tree’s 19 Notes. Always learn a new technique using a fresh import of the Example.gramps
file into a new blank tree.)
Then with the Notes category active, open Isotammi’s SuperTool addon tool and use File
→ Open
to load the script transcribed below. Test the script with the Execute… but make certain to set the “Filtered objects” radio button and have “Commit changes” deselected until after successful testings. After confirming the list shows the correct records would update, enable the “Commit changes” and Execute a final time.
View
→ Configure
options
Save the following as text file named : SuperTool-Notes Privacy.script
[Gramps SuperTool script file]
version=1
[title]
SuperTool-Notes Privacy
[category]
Notes
[initial_statements]
# A simple script to change the Gramps Privacy "padlock" Oct2022 # of filtered Notes to locked
# completely UNSAFE. Make a backup before running
# source: https://gramps.discourse.group/t/how-to-set-private-record-for-multiple-people/2885/3
[statements]
myinitprivacy = note.get_privacy()
note.set_privacy(True)
myendprivacy = note.get_privacy()
[filter]
[expressions]
note, myinitprivacy, myendprivacy
[scope]
filtered
[unwind_lists]
False
[commit_changes]
True
[summary_only]
False
The only line that’s vital in the script above is:
[statements]
note.set_privacy(True)
All the rest is about feedback & double-checking myself.
I think if you change note by obj that script will be available in any category
Thanks again, I’ve done the job manually already, but I’ll keep on eye on this thread if I need to do this in the future.
[Gramps SuperTool script file]
version=1
[title]
SuperTool-Set Privacy
[category]
[initial_statements]
# SuperTool-Set Privacy.script : A simple script to change the Gramps Privacy "padlock" of View objects to locked
# Completely without error handling. Make a backup before running
# discussion: https://gramps.discourse.group/t/batch-editing-elements/3552
# 23 Apr 2023 B.McCullough
[statements]
myinitprivacy = obj.get_privacy()
obj.set_privacy(True)
myendprivacy = obj.get_privacy()
[filter]
[expressions]
obj, myinitprivacy, myendprivacy
[scope]
selected
[unwind_lists]
False
[commit_changes]
False
[summary_only]
False
Since this thread was written, a SuperTool extension (getargs.py
or GetArguments) has been added to allow User selectable input to offer a pop-up list or checkbox in addition to a type-in textbox.
So now there is a Checkbox that lets you Set Privacy if selected, and Clear Privacy if deselected:
@include
statement to make those option available. For now, that script reads:
[Gramps SuperTool_beta script file]
version=1
[title]
SuperTool-Object Privacy
[category]
People
[initial_statements]
# A simple script to change the Gramps Privacy "padlock" Oct2022 # of selected Category object to locked
# completely UNSAFE. Make a backup before running
# based on: https://gramps.discourse.group/t/how-to-set-private-record-for-multiple-people/2885/3
@include getargs.py
args = getargs2(myTestLevel=("Set Privacy: ", bool, True))
counter = 0
[statements]
myInitPrivacy = obj.get_privacy()
if obj.get_privacy() != args.myTestLevel:
obj.set_privacy(args.myTestLevel)
counter +=1
else:
None
[filter]
[expressions]
name, myInitPrivacy, obj.get_privacy(), counter
[scope]
selected
[unwind_lists]
False
[commit_changes]
False
[summary_only]
False
Can such a script be made to work in ANY category? Every time that I save a Script as a Note, it sets the blank universal [category] back to the current category.
We’ve spoken before about documenting an example of wrapping a SuperTool script in an Addon Tool.
This seems like a good opportunity. Setting Privacy is a common need. And the thread here shows a Privacy script evolving from a narrow scope (in the Notes category only). And then showing how to validating the outcome before using the “commit-changes”
It then evolved to be usable in any category and then added a GetArguments example.
(Another expansion to this thread might be to demonstrate how to add a Filter selector. But that is a luxury.)
Can you describe what changes are needed to make the script work as an add-on Tool? Consider the process of making a plugin and publishing it to a GitHub repository as already covered.
The big questions are:
Every time that I save a Script as a Note, it sets the blank universal [category] back to the current category.
Yes, Supertool always sets the category as the current category when saving a script. This is a design mistake - Supertool should support multiple categories better. Note however, that a script can still work in any category even if there is a warning when the script is loaded.
One possible scenario:
Supertool provides the function ‘supertool_execute’. This function can be invoked in any addon and it can execute any Supertool code. The code to set the privacy attribute would be something like
from supertool_utils import supertool_execute
rsp = supertool_execute(category='Notes', db=db,
handles=handles, statements='obj.set_privacy(True)')
The answers to the two questions are
That’s wonderful!!! Thanks
OK. That example is executing a single SuperTool Script statement.
How about if I want to use an entire script? Can I pass an entire Script through the supertool_utils
with supertool_execute
? Or is it necessary to use the script as an outline for a plugin?
This is not yet documented in the README but there is also the function ‘supertool_execute_script’ that can execute a complete script file. Its usage is like
rsp = supertool_execute_script(script, dbstate=None, db=None,
trans=None, handles=None, args="")
However, the [scope] in the script file is ignored and the ‘handles’ parameter is used instead.