Skip to content

Commit e04f556

Browse files
committed
Add a script for setting Finder comments
1 parent 0327b5e commit e04f556

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

macos/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ scripts = [
6868
"usage": "set_accent_colour (red|orange|yellow|green|blue|purple|pink|graphite)",
6969
"description": "set the accent colour, as configured in the Appearance settings",
7070
},
71+
{
72+
"usage": "set_finder_comment PATH COMMENT",
73+
"description": "Set the Finder comment of a file, which will be indexed by Spotlight for searching"
74+
},
7175
{
7276
"usage": "sterilise [PATH]",
7377
"description": "alias for <code>xattr -d com.apple.quarantine</code>"
@@ -208,6 +212,15 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
208212
set the accent colour, as configured in the Appearance settings
209213
</dd>
210214

215+
<dt>
216+
<a href="https://github.com/alexwlchan/scripts/blob/main/macos/set_finder_comment">
217+
<code>set_finder_comment PATH COMMENT</code>
218+
</a>
219+
</dt>
220+
<dd>
221+
Set the Finder comment of a file, which will be indexed by Spotlight for searching
222+
</dd>
223+
211224
<dt>
212225
<a href="https://github.com/alexwlchan/scripts/blob/main/macos/sterilise">
213226
<code>sterilise [PATH]</code>
@@ -238,4 +251,4 @@ cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
238251
</p>
239252
</dd>
240253
</dl>
241-
<!-- [[[end]]] (checksum: dd3558b095357994d6bd03ab9bdc8481) -->
254+
<!-- [[[end]]] (checksum: d3812e637239eb78235f9823c0af4b7c) -->

macos/set_finder_comment

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
if (( $# != 2 ))
7+
then
8+
echo "Usage: $0 PATH COMMENT" >&2
9+
exit 1
10+
fi
11+
12+
# $ set_finder_comment src/_posts/2012/2012-12-30-hypercritical.md Hypercritical
13+
# 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)
14+
FILE_PATH="$(realpath "$1")"
15+
COMMENT="$2"
16+
17+
osascript -e '
18+
on run argv
19+
set filepath to (POSIX file (item 1 of argv) as alias)
20+
tell application "Finder" to set the comment of filepath to (item 2 of argv)
21+
end run
22+
' "$FILE_PATH" "$COMMENT"

0 commit comments

Comments
 (0)