Files
2026-02-16 15:05:15 +01:00

39 lines
1.3 KiB
Bash

#!/bin/bash
#
# Search program for recipes.
# version 2
# Clean out results folder
rm -rf /Users/90022300/Desktop/Neuer\ Ordner/results/*
# rm -rf ~/Users/90022300/Desktop/Neuer\ Ordner/.search/results/*
# Display the search dialog
query=$(osascript <<-EOF
set front_app to (path to frontmost application as Unicode text)
tell application front_app to get text returned of (display dialog "Search for:" default answer "" with title "Recipe Search")
EOF)
# If query is empty (nothing was typed), exit
if [ "$query" = "" ]
then
exit
fi
echo "Searching for \"$query\"."
# Search for query and (hard) link. The output from 'ln -v' is stored in results
# 'ln' complains if you search for the same thing twice... mdfind database lagging?
results=$(mdfind -0 -onlyin ~/Users/90022300/Desktop/Neuer\ Ordner/ "$query" | xargs -0 -J % ln -fv % ~/Users/90022300/Desktop/Neuer\ Ordner/.search/results)
if [ "$results" ]
then
# Results were found, open the folder
open ~/Users/90022300/Desktop/Neuer\ Ordner/.search/results/
else
# No results found, display a dialog
osascript <<-EOF
beep
set front_app to (path to frontmost application as Unicode text)
tell application front_app to display dialog "No results found for \"" & "$query" & "\"." buttons "Close" default button 1 with icon 0
EOF
fi