Search code examples
bashmacos-sierraautomatorfinder

After creating files via shell script, can it also be used to select those files in Finder?


I have an Automator service using shell script to create symbolic links for files/folders selected in Finder. But is there some way I could also make it select the symbolic links that are created in Finder after creating them?

Here's the script, run as /bin/bash:

for f in "$@"
    do  ln -s "$f" "${f}.deleteThisExtensionAfterMoving"
done

Hopefully there is a way to do this. If anyone knows how, please answer and let me know. Thanks!


Solution

  • The ln command doesn't return the path of the created link, but the script can echo the link path so that it can be passed on to the next action. The following example workflow will reveal the created links in the Finder (note that there isn't any error handling):

    Ask for Finder Items (or whatever)

    Run Shell Script {pass input as arguments}

       for f in "$@"
       do
          ln -s "$f" "${f}.deleteThisExtensionAfterMoving"
          echo "${f}.deleteThisExtensionAfterMoving"
       done
    

    Reveal Finder Items