Add Obsidian config scripts

This adds two scripts for Obsidian vaults.
One will get the values of showInlineTitle for all vaults
The other will change the value to false in all vaults
This commit is contained in:
Tracey Clark 2024-06-08 15:42:30 -05:00
commit 2c82137a71
5 changed files with 95 additions and 37 deletions

3
.gitignore vendored
View file

@ -1,5 +1,6 @@
*~
*.swp
*.*swp
.vstags
*.tdy
*.bak
@ -15,4 +16,4 @@
.history/
# Built Visual Studio Code Extensions
*.vsix
*.vsix

View file

@ -16,3 +16,5 @@ Miscellaneous scripts, e.g. set screen brightness from command line (bug workaro
* Backup and restore scripts for packages installed on Solus OS
* Set up a Solus OS development environment (update needed)
* Backup and restore scripts for Linux systems
* obsidian_hide_inlineTitle.py - Change all Obsidian vaults to hide inline titles
* obsidian_get_inlineTitle_values.py - Get the value of inlineTitle in all Obsidian vaults

View file

@ -0,0 +1,42 @@
#!/usr/bin/env python3
import os
import json
# Find all app.json config files for Obsidian
# in all subdirectories of the specified directory
# and show the value of showInlineTitle
# Assisted by ChatGPT
def get_show_inline_title_from_obsidian_folders(parent_directory):
try:
# Loop through all folders and subfolders in the parent directory
for root, dirs, files in os.walk(parent_directory):
# Check if the current directory is named ".obsidian"
if '.obsidian' in dirs:
obsidian_folder_path = os.path.join(root, '.obsidian')
# Look for a file named "app.json" in this folder
app_json_path = os.path.join(obsidian_folder_path, 'app.json')
if os.path.exists(app_json_path):
# Open the JSON file for reading
with open(app_json_path, 'r') as json_file:
data = json.load(json_file)
# Check if 'showInlineTitle' key exists
# and print its value
if 'showInlineTitle' in data:
print(
f"In '{app_json_path}': showInlineTitle is {data['showInlineTitle']}")
else:
print(
f"In '{app_json_path}': showInlineTitle key does not exist.")
except FileNotFoundError:
print(f"Error: Directory '{parent_directory}' not found.")
except json.JSONDecodeError:
print(f"Error: Invalid JSON file found in '{parent_directory}'.")
# Get the parent directory path from user input
parent_directory = input("Enter the parent directory path: ")
get_show_inline_title_from_obsidian_folders(parent_directory)

49
obsidian_hide_inlineTitle.py Executable file
View file

@ -0,0 +1,49 @@
#!/usr/bin/env python3
import os
import json
# Find all app.json config files for Obsidian
# in all subdirectories of the specified directory
# and change showInlineTitle to false
# Assisted by ChatGPT
def obsidian_hide_inline_title(parent_directory):
try:
# Loop through all folders and subfolders in the parent directory
for root, dirs, files in os.walk(parent_directory):
# Check if the current directory is named ".obsidian"
if '.obsidian' in dirs:
obsidian_folder_path = os.path.join(root, '.obsidian')
# Look for a file named "app.json" in this folder
app_json_path = os.path.join(obsidian_folder_path, 'app.json')
if os.path.exists(app_json_path):
# app_json_path = os.path.join(
# obsidian_folder_path, 'app.json')
# Open the JSON file for reading
with open(app_json_path, 'r') as json_file:
data = json.load(json_file)
# Check if 'showInlineTitle' key exists
# and change its value if it's 'true'
if 'showInlineTitle' in data and data['showInlineTitle'] == True:
data['showInlineTitle'] = False
# Open the same JSON file for writing
# and update its content
with open(app_json_path, 'w') as json_file:
json.dump(data, json_file, indent=4)
print(
f"Value of 'showInlineTitle' changed to false in '{app_json_path}'.")
else:
print(
f"No action needed in '{app_json_path}'. 'showInlineTitle' either doesn't exist or is already false.")
except FileNotFoundError:
print(f"Error: Directory '{parent_directory}' not found.")
except json.JSONDecodeError:
print(f"Error: Invalid JSON file found in '{parent_directory}'.")
# Get the parent directory path from user input
parent_directory = input("Enter the parent directory path: ")
obsidian_hide_inline_title(parent_directory)

View file

@ -1,36 +0,0 @@
#!/usr/bin/fish
set HOME /home/$USER
if set -q HOME
echo HOME variable defined as $HOME
end
if string length -q -- $HOME
echo "Backup up $HOME/.config"
cp -r $HOME/.config $HOME/.config.bak
echo "Deleting KDE config files"
set fileList Trolltech.conf akregatorrc baloofilerc bluedevilglobalrc kactivitymanagerd-statsrc
set -a fileList kactivitymanagerdrc kactivitymanagerd-pluginsrc kateschemarc kcmfonts kcminputrc kconf_updaterc kded5rc
set -a fileList kdeglobals kfontinstuirc kglobalshortcutsrc khotkeysrc kmixctrlrc kmixrc
set -a fileList kscreenlockerrc ksmserverrc ksplashrc ktimezonedrc kwinrc kwinrulesrc plasma-localerc
set -a fileList plasma-nm plasma-org.kde.plasma.desktop-appletsrc plasmarc plasmashellrc
set -a fileList powermanagementprofilesrc startupconfig startupconfigfiles startupconfigkeys
set -a fileList krunnerrc touchpadxlibinputrc systemsettingsrc kxkbrc PlasmaUserFeedback
set -a fileList kde.org/* kiorc klipperrc knfsshare kuriikwsfilterrc kwalletmanager5rc kwalletrc
set -a fileList plasma.emojierrc plasmanotifyrc PlasmaUserFeedback powerdevilrc kgammarc
set -a fileList kded_device_automounterrc device_automounter_kcmrc klaunchrc
set -a fileList trashrc kactivitymanagerd-switcher gtkrc-2.0 gtkrc baloofileinformationrc
set -a fileList breezerc
rm $fileList
echo "Deletion completed"
else
echo "HOME variable not defined"
end