Last active
March 7, 2024 16:37
-
-
Save luckman212/d2570b072fd1698492b0e17183990004 to your computer and use it in GitHub Desktop.
Self contained version that should fully work for generating Markdown links via Service Station [REQUIRES Python3 from Homebrew!]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| ############################################### | |
| ### requires python3 installed via Homebrew ### | |
| ############################################### | |
| unset TARGETED_URL | |
| MENU_KIND=-1 | |
| SELECTED_ITEM_URLS=() | |
| _pfx() { | |
| case $(arch) in | |
| arm64) echo '/opt/homebrew';; | |
| *) echo '/usr/local';; | |
| esac | |
| } | |
| py3=$(_pfx)/bin/python3 | |
| _realpath() { | |
| $py3 -c 'import sys,os; print(os.path.realpath(sys.argv[1]));' "$1" | |
| } | |
| _urlenc() { | |
| $py3 -c 'import sys; from urllib.parse import quote,unquote; print(quote(unquote(sys.argv[1])));' "$1" | |
| } | |
| _canonicalize() { | |
| unset canonical | |
| if [[ $1 =~ ^(/System/Volumes/Data)(/.*)$ ]]; then | |
| canonical="${BASH_REMATCH[2]}" | |
| fi | |
| if [[ -n $canonical ]]; then | |
| inode1=$(stat -f'%i' "$1") | |
| inode2=$(stat -f'%i' "$canonical") | |
| if [[ $inode1 -eq $inode2 ]]; then | |
| fullpath="$canonical" | |
| fi | |
| fi | |
| } | |
| _markdown() { | |
| fullpath=$(_realpath "$1") | |
| _canonicalize "$fullpath" | |
| filename="${fullpath##*/}" | |
| safe=$(_urlenc "${fullpath}") | |
| ext=$(tr '[:upper:]' '[:lower:]' <<<"${filename##*.}") | |
| case $ext in | |
| gif|jpg|jpeg|png) | |
| name="${filename%.*}" | |
| echo "" | |
| ;; | |
| *) | |
| echo "[$filename](file://$safe)" | |
| ;; | |
| esac | |
| } | |
| IFS='' | |
| while [[ $# -gt 0 ]]; do | |
| case $1 in | |
| -targetedURL) | |
| TARGETED_URL=$2; | |
| shift 2 | |
| ;; | |
| -menuKind) | |
| MENU_KIND=$2; | |
| shift 2 | |
| ;; | |
| -selectedItemURLs) | |
| shift | |
| ;; | |
| *) | |
| SELECTED_ITEM_URLS+=("$1") | |
| shift | |
| ;; | |
| esac | |
| done | |
| if [[ "${#SELECTED_ITEM_URLS}" -gt 0 ]]; then | |
| for f in "${SELECTED_ITEM_URLS[@]}"; do | |
| _markdown "$f" | |
| done | pbcopy | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No problem. I don't mind trying to help. But, it's very strange. Yes the script seems to be working. So I would really focus on your Privacy & Security settings.
Maybe Service Station lost it's grant for Full Disk Access. I have definitely experienced a bug on macOS where even though the app is listed in FDA, something is broken underneath the surface. Usually removing the app and then re-adding it corrects this (if that is indeed your issue)