-
-
Save luckman212/d2570b072fd1698492b0e17183990004 to your computer and use it in GitHub Desktop.
| #!/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 |
@Edomenegaz There was a missing ;; closure in one of the case statements which I just corrected above, but I don't think that was causing your issue.
If you run the script manually via the Terminal (not from within Service Station) e.g.
/path/to/obsidian_link2.sh 'abc/def/this is a test'
And then paste the contents of your clipboard, what do you get then?
@luckman212 First of all, I really appreciate your help. I don't want to waste your time, so don't bother too much if you have more important things to do 😄 If we can't make it work, I'll think about a different solution.
However, here's the content of the clipboard after running the script via Terminal.
[this is a test](file:///Users/myUser/abc/def/this%20is%20a%20test)
It seems to be working correctly here, right?
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)
This outputs respectively:
Python 3.9.5hello%20world