Created
January 8, 2023 07:33
-
-
Save pifabs/f3d9f745ca545dc6cbed5438a5e9a5af to your computer and use it in GitHub Desktop.
A gedit Exernal Tool that saves a note as an .md file to your obsidian vault
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import shutil | |
import os | |
# Get the current file's path and name | |
current_file_path = os.getenv('GEDIT_CURRENT_DOCUMENT_PATH') | |
current_file_name = os.path.basename(current_file_path) | |
# Set the destination directory and file extension | |
dst_dir = "<path to your obisdian vault>/Fleeting Notes" | |
file_ext = ".md" | |
# Move the file to the destination directory | |
try: | |
shutil.move(current_file_path, dst_dir) | |
print("File moved to: " + dst_dir) | |
except shutil.Error as e: | |
print("Error occurred while moving the file:", e) | |
# Rename the file to have the .md extension | |
old_path = os.path.join(dst_dir, current_file_name) | |
# Check if the file does not have the .md extension | |
if not current_file_name.endswith('.md'): | |
# Append .md to the file name | |
new_path = os.path.join(dst_dir, current_file_name + '.md') | |
else: | |
# Use the current file name as is | |
new_path = os.path.join(dst_dir, current_file_name) | |
# Check if the file already exists | |
if os.path.exists(new_path): | |
raise FileExistsError("File already exists: " + new_path) | |
try: | |
os.rename(old_path, new_path) | |
except OSError as e: | |
print("Error occurred while renaming the file:", e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment