Open a file that was just created through a shell command #395
-
I'm having trouble figuring out which reply goes with which of my many questions in this discussion here #369 (reply in thread) so I wanted to ask this again. First, thanks so much for creating this plugin, it's super helpful for me, and thanks also for taking the time to reply! I have a shell command: This runs the script
I don't remember exactly who helped me with this script, it might have been you or someone on another forum, either way it works as intended. It takes files and renames them. However, to add the cherry on top, I'd like it to automatically navigate to that new file. I've tried following your solution here #369 (reply in thread) but when I set my But then I get this error pop up: It’s somehow taking the command to copy as a file name I guess, though I don't know where it's getting that from. Any advice is appreciated. Thanks!! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi! 🙂 Thank you for your question and nice feedback! 🌞 The problem is that echo "copy $fileName to $newFileName" To fix this, you could change the echo "$newFileName" Then, if you still would like to see a notification balloon in Obsidian showing the text that was originally echoed, you can output that text to echo "$newFileName"
echo "copy $fileName to $newFileName" 1>&2 So, this is what happens now:
Please let me know if this helped you, or if you still have any questions. 👍 Here are the above-mentioned changes edited in your #!/bin/bash
fileName=$1
today=$(date +"%Y-%m-%d")
if [[ $fileName =~ ([0-9]+-[0-9]+-[0-9]+)(.*)([0-9]+)\.([^.]*) ]]; then
# BASH_REMATCH match groups:
# 1 - date
# 2 - everything else
# 3 - number
# 4 - extension
number=$(( ${BASH_REMATCH[3]} + 1 ))
while :; do
newFileName="$(date +%Y-%m-%d)${BASH_REMATCH[2]}${number}.${BASH_REMATCH[4]}"
[[ -f $newFileName ]] || break
let number++
done
# Open the new file in Obsidian:
echo "$newFileName"
# Show a notification baloon in Obsidian:
echo "copy $fileName to $newFileName" 1>&2
cp "$fileName" "$newFileName"
elif [[ $fileName =~ (.*)\.([^.]*) ]]; then
newNumber="1"
addInfoName="$today ${BASH_REMATCH[1]} V.${newNumber}.${BASH_REMATCH[2]}"
mv "$fileName" "$addInfoName"
let newNumber++
cp "$addInfoName" "$today ${BASH_REMATCH[1]} V.${newNumber}.${BASH_REMATCH[2]}"
# Open the new file in Obsidian:
echo "$today ${BASH_REMATCH[1]} V.${newNumber}.${BASH_REMATCH[2]}"
fi Edit: I also added the following to the # Open the new file in Obsidian:
echo "$today ${BASH_REMATCH[1]} V.${newNumber}.${BASH_REMATCH[2]}" |
Beta Was this translation helpful? Give feedback.
Hi! 🙂 Thank you for your question and nice feedback! 🌞
The problem is that
date-iterate.sh
is outputting the textcopy 2024-02-10 example V.2.md to 2024-02-16 example V.6.md
tostdout
:To fix this, you could change the
echo
line to only include the new file name:Then, if you still would like to see a notification balloon in Obsidian showing the text that was originally echoed, you can output that text to
stderr
:So, this is what happens now:
stdout
(standard output) by theecho
line that does not contain1>&2
. O…