Search code examples
bashservicefilesizeautomator

Get file size in Automator workflow


Creating a service in Automator (Run shell script > Bash) to copy to clipboard filesize (in bytes) of selected file in Finder. I'm not very well versed in bash, and can't see where this is wrong. Aim is to have it appear in the 'services' menu when right clicking a file, and then I can just paste the filesize wherever I fancy. Options I have selected in Automator are:

Service receives selected "files or folders" in "Finder.app"

Shell /bin/bash

Pass input as arguments

for f in "$@"
do
    getty=$(ls -l "$f")
done

IFS=' ' read -a newList <<< "${getty}"

echo -n ${newList[4]} | pbcopy

Run Shell Script failed - 1 error:

-: -c: line1: syntax error near unexpected token `do


Solution

  • To make it clearer to everyone, the solution is :

    1. create an empty automator script
    2. add action "get selected elements from Finder
    3. add action "Run shell script" with inputs as arguments
    4. with the following script :
     stat -f  '%z' "$@" | pbcopy