deek5 deek5 - 20 days ago 5
AppleScript Question

how make link on desktop or in dock with a service just press a right button all that in an applescript executed in automator

The following script is to be placed in a creation of service in automator.

Thus open Automator and select new service. For files and folder link they are placed on the desktop just application can be placed in the Dock ( you have the script below you can modifie all that you want.

On the left part of automator select utility, double click on Execute an script of applescript. In a right part you see window open, on the item " service receive a select " you choose " Files and Folders ".

Now below in window "Execute an Applescript " inside

" on run {input,parameters}"

you can put the script below.

on run {input, parameters}
set input to POSIX path of input

set fich to POSIX path of input

set ft to {}

set fold to {}

set sn to {}

set Nm to {}



set {file type:ft} to info for POSIX path of fich

if ft is not "APPL" then

set input to input

set vhdoudmg to input as Unicode text

set input to POSIX path of vhdoudmg

set sn to ""

try

set {name:Nm} to info for file vhdoudmg

end try

if sn is "" then

set lelien to "/Users/username/Desktop/

" & Nm

else

set lelien to "/Users/username/Desktop/

" & sn

end if

set vhdoudmg to do shell script "ln -s -v " & quoted form of input & " " & quoted form of lelien

else

set Reponse to display dialog " Choose to create the symbolic link on the Desktop or Application in the Dock " & return buttons {" The link on the Desktop ", " Application in the Dock "}

set Choix to button returned of Reponse



if " Application in the Dock " is in Choix then

try

set theFile to POSIX path of input

end try

try

tell application "Dock" to quit

end try

do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</k ey><string>" & theFile & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>' "

try

tell application "Dock" to activate

end try



else

set input to POSIX path of input



set vhdoudmg to input as Unicode text

set input to POSIX path of vhdoudmg

set fich to do shell script "echo " & input

try

set {name:Nm} to info for file vhdoudmg

end try

set lelien to "/Users/username/Desktop/" & Nm

set vhdoudmg to do shell script "ln -s -v " & quoted form of input & " " & quoted form of lelien



end if

end if

return input

end run


And now you can place this workflow in /Users/yourname/Library/Services and when you click rigth on your mouse button, il you go on context menu on Services in a choice you can see the name of this script ( the name which you would have given it during the creation.)

Thus open Automator and select new service. For files and folder link they are placed on the desktop just application can be placed in the Dock ( you have the script below you can modifie all that you want.

Answer

Good evening just for a shorter and just as effective script.

on run {input, parameters}
    set input to POSIX path of input
    set fich to POSIX path of input
    set ft to {}
    set Nm to {}

        set {name:Nm,file type:ft} to info for POSIX path of fich

            set input to input
            set vhdoudmg to input as Unicode text
            set input to POSIX path of vhdoudmg
                    set lelien to "/Users/username/Desktop/" & Nm


                if ft is not "APPL" then
            set vhdoudmg to do shell script "ln -s -v " & quoted form of input & " " & quoted form of lelien
        else
set Reponse to display dialog " Choose to create the symbolic link on the Desktop or Application in the Dock " & return buttons {" The link on the Desktop ", " Application in the Dock "}

    set Choix to button returned of Reponse
   if " Application in the Dock " is in Choix then
                try
                    set theFile to POSIX path of input
                end try
                try
                    tell application "Dock" to quit
                end try
                do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theFile & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
                try
                    tell application "Dock" to activate
                end try

            else

                set vhdoudmg to do shell script "ln -s -v " & quoted form of input & " " & quoted form of lelien

            end if
        end if
    return input
end run