How can I create a Finder alias in a bash script that reads arguments from the command-line?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







5















I'd like to write a bash script that takes 2 inputs:




  1. path to actual file

  2. path of a Finder alias file (not a unix link) to be created that refers to 1.


The bash script should pass these inputs to an automation script that creates the alias.



I've seen How to use AppleScript in a bash script to create an alias for an app? but I have not been able to adapt it for my goal.



How can I do this?










share|improve this question





























    5















    I'd like to write a bash script that takes 2 inputs:




    1. path to actual file

    2. path of a Finder alias file (not a unix link) to be created that refers to 1.


    The bash script should pass these inputs to an automation script that creates the alias.



    I've seen How to use AppleScript in a bash script to create an alias for an app? but I have not been able to adapt it for my goal.



    How can I do this?










    share|improve this question

























      5












      5








      5


      1






      I'd like to write a bash script that takes 2 inputs:




      1. path to actual file

      2. path of a Finder alias file (not a unix link) to be created that refers to 1.


      The bash script should pass these inputs to an automation script that creates the alias.



      I've seen How to use AppleScript in a bash script to create an alias for an app? but I have not been able to adapt it for my goal.



      How can I do this?










      share|improve this question














      I'd like to write a bash script that takes 2 inputs:




      1. path to actual file

      2. path of a Finder alias file (not a unix link) to be created that refers to 1.


      The bash script should pass these inputs to an automation script that creates the alias.



      I've seen How to use AppleScript in a bash script to create an alias for an app? but I have not been able to adapt it for my goal.



      How can I do this?







      terminal finder bash automation alias






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 2 at 9:00









      foundartfoundart

      1283




      1283






















          1 Answer
          1






          active

          oldest

          votes


















          3














          With minimal error handling:



          #!/bin/sh

          [ -f "$1" ] || exit 1
          [ "$2" ] || exit 1

          alias=$(basename "$2")

          /usr/bin/osascript <<EOF
          tell application "Finder"
          set myapp to POSIX file "$1" as alias
          make new alias to myapp at Desktop
          set name of result to "$alias"
          end tell
          EOF

          mv ~/Desktop/"$alias" "$2"





          share|improve this answer































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            With minimal error handling:



            #!/bin/sh

            [ -f "$1" ] || exit 1
            [ "$2" ] || exit 1

            alias=$(basename "$2")

            /usr/bin/osascript <<EOF
            tell application "Finder"
            set myapp to POSIX file "$1" as alias
            make new alias to myapp at Desktop
            set name of result to "$alias"
            end tell
            EOF

            mv ~/Desktop/"$alias" "$2"





            share|improve this answer




























              3














              With minimal error handling:



              #!/bin/sh

              [ -f "$1" ] || exit 1
              [ "$2" ] || exit 1

              alias=$(basename "$2")

              /usr/bin/osascript <<EOF
              tell application "Finder"
              set myapp to POSIX file "$1" as alias
              make new alias to myapp at Desktop
              set name of result to "$alias"
              end tell
              EOF

              mv ~/Desktop/"$alias" "$2"





              share|improve this answer


























                3












                3








                3







                With minimal error handling:



                #!/bin/sh

                [ -f "$1" ] || exit 1
                [ "$2" ] || exit 1

                alias=$(basename "$2")

                /usr/bin/osascript <<EOF
                tell application "Finder"
                set myapp to POSIX file "$1" as alias
                make new alias to myapp at Desktop
                set name of result to "$alias"
                end tell
                EOF

                mv ~/Desktop/"$alias" "$2"





                share|improve this answer













                With minimal error handling:



                #!/bin/sh

                [ -f "$1" ] || exit 1
                [ "$2" ] || exit 1

                alias=$(basename "$2")

                /usr/bin/osascript <<EOF
                tell application "Finder"
                set myapp to POSIX file "$1" as alias
                make new alias to myapp at Desktop
                set name of result to "$alias"
                end tell
                EOF

                mv ~/Desktop/"$alias" "$2"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 2 at 10:00









                nohillsidenohillside

                53.3k14112157




                53.3k14112157















                    Popular posts from this blog

                    Plaza Victoria

                    Puebla de Zaragoza

                    Musa