Add a script for copying files into Obsidian
- ID
1c3e08a- date
2024-01-05 12:03:41+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
0b94491- message
Add a script for copying files into Obsidian- changed files
2 files, 48 additions, 1 deletion
Changed files
textexpander/README.md (2214) → textexpander/README.md (2771)
diff --git a/textexpander/README.md b/textexpander/README.md
index 7026817..8131db2 100644
--- a/textexpander/README.md
+++ b/textexpander/README.md
@@ -18,6 +18,12 @@ folder_name = "textexpander"
scripts = [
{
+ "name": "copy_file_into_obsidian.py",
+ "description": """
+ get the latest download from my Desktop, copy it into Obsidian, and print a ![[…]] link to insert it into my current document.
+ """
+ },
+ {
"name": "get_mastodon_text.py",
"description": """
print a Markdown-formatted blockquote of a Mastodon I've got open in Safari, suitable for saving in Obsidian
@@ -47,6 +53,15 @@ cog_helpers.create_description_table(
]]]-->
<dl>
<dt>
+ <a href="https://github.com/alexwlchan/scripts/blob/main/textexpander/copy_file_into_obsidian.py">
+ <code>copy_file_into_obsidian.py</code>
+ </a>
+ </dt>
+ <dd>
+ get the latest download from my Desktop, copy it into Obsidian, and print a ![[…]] link to insert it into my current document.
+ </dd>
+
+ <dt>
<a href="https://github.com/alexwlchan/scripts/blob/main/textexpander/get_mastodon_text.py">
<code>get_mastodon_text.py</code>
</a>
@@ -74,4 +89,4 @@ cog_helpers.create_description_table(
print a Markdown-formatted blockquote of a tweet I've got open in Safari, suitable for saving in Obsidian
</dd>
</dl>
-<!-- [[[end]]] (checksum: ef5c5561422a830e36c0bb6498b552a9) -->
+<!-- [[[end]]] (checksum: 6e089377a506a73c7859d6e34777570a) -->
textexpander/copy_file_into_obsidian.py (0) → textexpander/copy_file_into_obsidian.py (647)
diff --git a/textexpander/copy_file_into_obsidian.py b/textexpander/copy_file_into_obsidian.py
new file mode 100755
index 0000000..dc4ca04
--- /dev/null
+++ b/textexpander/copy_file_into_obsidian.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+import datetime
+import os
+import subprocess
+
+
+if __name__ == "__main__":
+ latest_download = (
+ subprocess.check_output(["/Users/alexwlchan/repos/scripts/fs/latest_download"])
+ .strip()
+ .decode("utf8")
+ )
+
+ name = os.path.basename(latest_download)
+
+ out_dir = os.path.join(
+ os.environ["HOME"],
+ "textfiles",
+ "Attachments",
+ str(datetime.datetime.now().year),
+ )
+
+ os.makedirs(out_dir, exist_ok=True)
+
+ out_path = os.path.join(out_dir, name)
+
+ assert not os.path.exists(out_path)
+
+ os.rename(latest_download, out_path)
+
+ print(f"![[{name}]]")