Pick branding images with the portal file chooser

omarchy-file-select gains an --extensions filter, passed through the
portal's native filters option, so the branding commands can offer
only png/svg instead of walking a find-generated menu of Pictures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-08-01 19:55:02 -05:00
co-authored by Claude Fable 5
parent 84e87ce67e
commit 87940c3cf4
3 changed files with 22 additions and 14 deletions
+2 -4
View File
@@ -8,12 +8,10 @@
set -euo pipefail
SOURCE_DIR="${XDG_PICTURES_DIR:-$HOME/Pictures}"
case "${1:-}" in
image)
image=$(omarchy-menu-file "Pick png/svg from $SOURCE_DIR" "${SOURCE_DIR}" "svg png")
if [[ -n $image ]] && omarchy-transcode-ascii "$image" ~/.config/omarchy/branding/about.txt --width 54 --height 26; then
image=$(omarchy-file-select --title "Pick PNG or SVG for About" --extensions "png svg")
if omarchy-transcode-ascii "$image" ~/.config/omarchy/branding/about.txt --width 54 --height 26; then
omarchy-launch-about >/dev/null 2>&1
fi
;;
+2 -4
View File
@@ -8,12 +8,10 @@
set -euo pipefail
SOURCE_DIR="${XDG_PICTURES_DIR:-$HOME/Pictures}"
case "${1:-}" in
image)
image=$(omarchy-menu-file "Pick png/svg from $SOURCE_DIR" "${SOURCE_DIR}" "svg png")
if [[ -n $image ]] && omarchy-transcode-ascii "$image" ~/.config/omarchy/branding/screensaver.txt; then
image=$(omarchy-file-select --title "Pick PNG or SVG for screensaver" --extensions "png svg")
if omarchy-transcode-ascii "$image" ~/.config/omarchy/branding/screensaver.txt; then
omarchy-launch-screensaver force >/dev/null 2>&1
fi
;;
+18 -6
View File
@@ -1,8 +1,8 @@
#!/usr/bin/python3
# omarchy:summary=Pick files with the desktop file chooser
# omarchy:args=[--title <title>] [--multiple]
# omarchy:examples=omarchy file select --title "Send with Tailscale" --multiple
# omarchy:args=[--title <title>] [--multiple] [--extensions "<ext ext...>"]
# omarchy:examples=omarchy file select --title "Send with Tailscale" --multiple | omarchy file select --title "Pick image" --extensions "png svg"
# Python rather than bash, alone among the commands here, because the portal
# answers a request with a Response signal addressed to the connection that
@@ -36,6 +36,7 @@ def main():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--title", default="Select file")
parser.add_argument("--multiple", action="store_true")
parser.add_argument("--extensions", default="")
args, unknown = parser.parse_known_args()
if unknown:
@@ -71,15 +72,26 @@ def main():
predicted = "/org/freedesktop/portal/desktop/request/%s/%s" % (sender, token)
subscribe(predicted)
options = {
"handle_token": GLib.Variant("s", token),
"multiple": GLib.Variant("b", args.multiple),
}
if args.extensions:
# Glob matching in the chooser is case-sensitive, so cover both cases.
exts = [ext.lstrip(".").lower() for ext in args.extensions.split()]
patterns = [(0, "*." + ext) for ext in exts] + [(0, "*." + ext.upper()) for ext in exts]
label = " ".join("*." + ext for ext in exts)
filters = GLib.Variant("a(sa(us))", [(label, patterns)])
options["filters"] = filters
options["current_filter"] = GLib.Variant("(sa(us))", (label, patterns))
handle = bus.call_sync(
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.FileChooser",
"OpenFile",
GLib.Variant("(ssa{sv})", ("", args.title, {
"handle_token": GLib.Variant("s", token),
"multiple": GLib.Variant("b", args.multiple),
})),
GLib.Variant("(ssa{sv})", ("", args.title, options)),
None,
Gio.DBusCallFlags.NONE,
-1,