[iOS/MacOS] [Siri Shortcut] [JB] [Git] Apply and switch between the same multiple settings for all vaults

In the last two months or so, I was trying to figure out how to optimize my work on the iPad. I have a large vault, so I needed to cut it up.
Then with all those temporary vaults, came other issues. First, when I installed and enabled a new plugin for A, I had to do the same for B-Z (which entailed copying the folder into the plugin folders of B-Z and appending each community-plugins.json file in B-Z).
I had to find a way to automate this.

Then, on the heels of that, I thought what do I need to switch between two sets of settings (e.g. day and night) and apply all changes to A-Z subvaults?
First, I was thinking URL schemes, or thought maybe the Obsidian Advanced URI plugin could help, but not every single case.

So I thought I could try and do it with git, and I finally managed to make it work.

My solution involves using two buttons (Shortcuts; I always keep the on the right in Slide-Over, as if it was an Edge Panel a la Android) that effect changes using git stash and git checkout.

Requirements

  1. A jailbroken device. JB’ing is pretty straightforward these days, e.g. with the Palera1n ISO (look it up).
  2. Filza JB file manager.
  3. Some expertise or proclivity to learn something about automation, namely iOS Shortcuts.
  4. NewTerm2 terminal: optional.
  5. As this deals with a git repo from the onset, ostensibly you’d need git. If you are using Obsidian sync, you need to figure out a different way with A-Shell, dealing with search and replace in files.

Setup

I’m assuming you’ve jailbroken your device and installed Filza already.

In order to provide a one-button solution, what we need to do is SSH into our own device’s Localhost.

  • In Filza, go into /etc/ssh and open sshd_config in the text editor of Filza.
    Where you see the line # Port 22, type underneath Port 2222 without the hash (the hash stands for comment, now it will be a setting). Save and exit the file.
  • You can also un-hash the line with port 22, but we’ll be using port 2222 later.

We can head over to our Shortcuts app. I am assuming you already have some shortcuts to do with Obsidian.
Here I’ll just show you how to call these shortcuts silently in SSH.

I am only showing the “difficult” part here, so this can be incorporated into your shortcut e.g. one that runs pull from your remote first, etc.

  • Create a new shortcut:

Search for and rag in “Run script over SSH”. For Host, type in 127.0.0.1, port will be 2222, user will be root, and for authentification, we use the Password method, where the default root password is alpine (type it in). Input is left empty.

In the script area, you need to change into a directory (cd) where your repo resides. You can use symbolic links in Filza beforehand. I am using the directory I was accessing git from in NewTerm2. I am using A to Z folders and was making changes to these files in those folders, so I am revoking the changes by checking them out, that is rolling back to what I had before I applied the stash, as per the instructions by Adam.
In my case, the following will cause light mode and different theme settings to be active in all of my subvaults, until (using another Shortcut) I re-apply the stash again to apply the dark mode.

Write in your code in your script area:

cd /var/mobile/<RepoName>
git checkout -- \[A-Z\]/.obsidian/appearance.json
git checkout -- \[A-Z\]/.obsidian/plugins/obsidian-style-settings/data.json

The first time I was running it, I received the error:
fatal: detected dubious ownership in repository at...
I followed the on-screen suggestion but nothing happened. I manually edited my config file, I even used the wildcard asterisk; nothing. Same error. Then it occurred to me to run the command from inside the Shortcut, in this very same SSH command, but instead of global I was using system:

cd /var/mobile/<RepoName>
git config --system --add safe.directory /private/var/mobile/Containers/Data/Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx/Documents/<RepoName>
  • Note: because the UUID of your Obsidian container/folder changes on each update of the app, it is worthwhile to have and run a shortcut that puts the new UUID into a global variable (of the ToolBox Pro app), and you can use that in all other shortcuts (better than updating your Obsidian PATH in a dozen shortcuts).

Then it was working properly.

The above only caters to a simple use case, yet. You can use multiple stashes and multiple lines in the SSH part of the shortcut, so you can apply various changes unto different vaults with the push of a button.

The first part of the setup went missing:

  • Make changes on PC on all your vaults. It is easier to set it up on PC first. Make sure that this particular commit will contain only changes you’d want to revert and stash later. In my case the 52 files in A-Z folders.
  • Pull your changes on mobile. Revert the last commit (with a temp shortcut or in NewTerm2, as I couldn’t make this work in A-Shell):
git revert <commit ID>

You will now have uncommited changes in the workspace. Save this batch of changes with stash:

git stash save "settingname"

You can apply these changes right back:

git stash apply
  • This applies the last/topmost stash. If you have more stashes, you need to specify which. See documentation online.

Then when all this is done, you can e.g. add an automation on mobile that at 2000 hrs runs a shortcut that involves discarding the changes by made by the stash (git checkout) and hence forces dark mode on all your (sub)vaults and some other settings you set up on PC beforehand.
Basically you can switch between ON and OFF states like this, based on changes you have made in a particular commit.

Using git stash is superior to using git revert because you can easily add more stashes if certain other changes happen to (become merged into) files you are using for switching modes.

It’s a busy weekend and sorry about posting all these in fits and starts.

There are certain precautions one needs to be mindful of (at least in my case I need to take heed of them):

  • I need to quit Obsidian so settings files will not be in use.
  • In the shortcut doing the checkout, I must first run a shortcut that moves my sub-vaults back under the main vault.

If there are any more caveats, I will hopefully remember to make note of those as well.