nk9 / get_dropbox_link

Code to get the URL of a file in the Dropbox folder
MIT License
6 stars 1 forks source link

get_dropbox_link.py CLI with multiple files returns all file URLs, but in Automator returns all URLs twice #9

Closed porg closed 1 year ago

porg commented 1 year ago

✅ Running the script in the shell returns as many URLs as files you provided

$ get_dropbox_link.py ~/Dropbox/Public/Media-Library-UI-differences-2023-05-23-1818.png
https://www.dropbox.com/s/xxx/Media-Library-UI-differences-2023-05-23-1818.png?dl=0

$ get_dropbox_link.py ~/Dropbox/Public/Media-Library-UI-differences-2023-05-23-18*     
https://www.dropbox.com/s/xxx/Media-Library-UI-differences-2023-05-23-1818.png?dl=0
https://www.dropbox.com/s/yyy/Media-Library-UI-differences-2023-05-23-1821.png?dl=0
https://www.dropbox.com/s/zzz/Media-Library-UI-differences-2023-05-23-1823.png?dl=0

❌ But in Automator the list of selected files in Finder is twice in $@ hence you also get the URLs twice

Shell Script in Automator


RESULT=$($HOME/bin/bin/get_dropbox_link.py "$@")

LOG="$HOME/Library/Logs/get_dropbox_link_debug.txt"

   echo INPUT: >> "$LOG"
     echo "$@" >> "$LOG"
          echo >> "$LOG"
  echo RESULT: >> "$LOG"
echo "$RESULT" >> "$LOG"
          echo >> "$LOG"

The log:

INPUT:
/Users/me/Dropbox/Public/Media-Library-UI-differences-2023-05-23-1821.png /Users/me/Dropbox/Public/Media-Library-UI-differences-2023-05-23-1818.png /Users/me/Dropbox/Public/Media-Library-UI-differences-2023-05-23-1823.png /Users/me/Dropbox/Public/Media-Library-UI-differences-2023-05-23-1821.png /Users/me/Dropbox/Public/Media-Library-UI-differences-2023-05-23-1818.png /Users/me/Dropbox/Public/Media-Library-UI-differences-2023-05-23-1823.png

RESULT:
https://www.dropbox.com/s/xxx/Media-Library-UI-differences-2023-05-23-1821.png?dl=0
https://www.dropbox.com/s/yyy/Media-Library-UI-differences-2023-05-23-1818.png?dl=0
https://www.dropbox.com/s/zzz/Media-Library-UI-differences-2023-05-23-1823.png?dl=0
https://www.dropbox.com/s/xxx/Media-Library-UI-differences-2023-05-23-1821.png?dl=0
https://www.dropbox.com/s/yyy/Media-Library-UI-differences-2023-05-23-1818.png?dl=0
https://www.dropbox.com/s/zzz/Media-Library-UI-differences-2023-05-23-1823.png?dl=0

Followup

porg commented 1 year ago

I had a working solution to cut the string in half

LIST="$@"

LISTHALF=$(echo $LIST | cut -c -$(echo "scale=0; $(echo $LIST | wc -c) / 2" | bc))

RESULT=$($HOME/bin/bin/get_dropbox_link.py "$LISTHALF")

LOG="$HOME/Library/Logs/get_dropbox_link_debug.txt"

   echo INPUT: >> "$LOG"
    echo $LIST >> "$LOG"
          echo >> "$LOG"
  echo HALFED: >> "$LOG"
echo $LISTHALF >> "$LOG"
          echo >> "$LOG"
  echo RESULT: >> "$LOG"
  echo $RESULT >> "$LOG"
          echo >> "$LOG"

# echo "$RESULT"

Only to notice this was not necessary, the solution is much simpler:

Get Dropbox URL - Automator gets file list twice

Followup

porg commented 1 year ago

Good news: Both the newest Readme.md and also the newest included Automator file don't have that "Get Selected Finder Items" block anymore. Seems I had an outdated earlier version and had to learn it the hard way myself. 😉

nk9 commented 1 year ago

Yep, I ran into the same issue and tweaked the code and README to fix it. Sorry you had to spend the time again, but hey: now you know a bit more about Automator, right? 😉

porg commented 1 year ago

Yes, and I learned how to cut a string in half in the Shell, haha!