Add a script for setting Finder comments
- ID
e04f556- date
2025-03-03 10:21:45+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
0327b5e- message
Add a script for setting Finder comments- changed files
2 files, 36 additions, 1 deletion
Changed files
macos/README.md (6940) → macos/README.md (7379)
diff --git a/macos/README.md b/macos/README.md
index e620ade..1eece27 100644
--- a/macos/README.md
+++ b/macos/README.md
@@ -69,6 +69,10 @@ scripts = [
"description": "set the accent colour, as configured in the Appearance settings",
},
{
+ "usage": "set_finder_comment PATH COMMENT",
+ "description": "Set the Finder comment of a file, which will be indexed by Spotlight for searching"
+ },
+ {
"usage": "sterilise [PATH]",
"description": "alias for <code>xattr -d com.apple.quarantine</code>"
},
@@ -209,6 +213,15 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
</dd>
<dt>
+ <a href="https://github.com/alexwlchan/scripts/blob/main/macos/set_finder_comment">
+ <code>set_finder_comment PATH COMMENT</code>
+ </a>
+ </dt>
+ <dd>
+ Set the Finder comment of a file, which will be indexed by Spotlight for searching
+ </dd>
+
+ <dt>
<a href="https://github.com/alexwlchan/scripts/blob/main/macos/sterilise">
<code>sterilise [PATH]</code>
</a>
@@ -238,4 +251,4 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
</p>
</dd>
</dl>
-<!-- [[[end]]] (checksum: dd3558b095357994d6bd03ab9bdc8481) -->
+<!-- [[[end]]] (checksum: d3812e637239eb78235f9823c0af4b7c) -->
macos/set_finder_comment (0) → macos/set_finder_comment (603)
diff --git a/macos/set_finder_comment b/macos/set_finder_comment
new file mode 100755
index 0000000..2da5d61
--- /dev/null
+++ b/macos/set_finder_comment
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+set -o errexit
+set -o nounset
+
+if (( $# != 2 ))
+then
+ echo "Usage: $0 PATH COMMENT" >&2
+ exit 1
+fi
+
+# $ set_finder_comment src/_posts/2012/2012-12-30-hypercritical.md Hypercritical
+# 2025-02-25 23:16:10.894 osascript[60436:891948] CFURLGetFSRef was passed a URL which has no scheme (the URL will not work with other CFURL routines)
+FILE_PATH="$(realpath "$1")"
+COMMENT="$2"
+
+osascript -e '
+ on run argv
+ set filepath to (POSIX file (item 1 of argv) as alias)
+ tell application "Finder" to set the comment of filepath to (item 2 of argv)
+ end run
+' "$FILE_PATH" "$COMMENT"