2

Currently, I'm trying to figure out how to open Obsidian Notes vaults from the File Explorer itself (instead of first opening up Obsidian and using the Vault browser).

To that end, the following command works (I'm using the Obsidian notes Appimage, which I prefer to a package style install):

#!/bin/bash
/home/username/Desktop/Obsidian-1.5.11.AppImage "obsidian://open?vault=testvault"

(the name of the vault, and hence the vault folder, is testvault)

I put the command in a .sh file which I saved within the vault folder itself.

I then open a terminal at the vault folder (opening a terminal is necessary, since when the script is run with a double click, the command doesn't work as intended, it doesn't open the indicated vault but merely the last opened vault), and then run the .sh file.

./openvault.sh

Now what I'd like to do is automatically close the terminal after the vault opened, without closing the Obsidian Notes app too.

To that end, I tried the following:

#!/bin/bash
/home/username/Desktop/Obsidian-1.5.11.AppImage "obsidian://open?vault=testvault" & disown && exit

# `&&` after `disown` so that `exit` only gets executed after disown is successfully executed

Now this only partially worked. In that it managed to execute the disown command. So that when I close the terminal with the close button of the terminal app, Obsidian Notes keeps running.

But the exit command doesn't execute. How to make that execute too?

Here's the terminal log of when the command is run:

2024-03-22 09:26:20 Loading main app package /tmp/.mount_Obsidi8hbnvd/resources/obsidian.asar
xdg-settings: default-url-scheme-handler not implemented for xfce
Received callback URL obsidian://open?vault=tesvault
2024-03-22 09:26:21 Checking for update using Github
2024-03-22 09:26:21 Success.
2024-03-22 09:26:21 Latest version is 1.5.11
2024-03-22 09:26:21 App is up to date.

The cursor just keeps blinking under the last line of the log, instead of the terminal returning to the username@machinename:/current/working/directory$ prompt.

1 Answer 1

1
  1. Scripts execute in new processes. It cannot itself exit from the parent interactive shell.
  2. Scripts execute in a new process. They don't need to dismiss a child if they are going to exit.
  3. A script could kill the parent process. DON'T!
  4. For the interactive shell to exit because of a command, the interactive shell must do it. In this case, you probably want to define an alias (in my bash manual, section 6.6) or shell function (3.3) to run a command and exit. Alternatively, one could invoke the script like exec ./openvault.sh to replace the interactive shell with the script.
  5. If the program stays running for a time (which your examples seem to indicate), you might want to detach it from the terminal. In Linux, you can do this using setsid, like: setsid /home/username/Desktop/Obsidian-1.5.11.AppImage ...
  6. You might be better off finding out what is in your desktop file, and doing that instead. After all, you might rename the file on your destktop, or move it to a folder, ... It probably is one or two commands already.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.