4

I used a symlink to make a shortcut on the desktop to a file

ln -s "~/My Scripts/start.sh" "Go go gadget hammer"

But realised I can't set an icon on a symlink.

So I used this script to make an alias:

osascript -e 'tell application "Finder" to make new alias at (path to desktop folder) to (("~/My Scripts/start.sh") as POSIX file)'

But I get this error

Finder got an error: Can't make class alias. (-2710)

How can I make a shortcut on the desktop and also give it a custom icon eventually?

0

2 Answers 2

0

This following code should give you a basic idea

tell application "Finder"
    set aliasFile to make new alias file ¬
        at folder (path to desktop folder) ¬
        to alias ((path to home folder as text) & "My Scripts:start.sh") with properties ¬
        {name:"Go go gadget hammer"}
end tell
2
  • At line 3 I get "expected end or end tell but found parameter name
    – user150109
    Commented Apr 21, 2023 at 15:30
  • 1
    Copy the code exactly how it is. Looks to me as if you forgot to paste the last line... the end tell
    – wch1zpink
    Commented Apr 21, 2023 at 15:45
0

You can make a shortcut on the Desktop with a custom icon as simply as this:

  1. In Finder, right-click the file you want the alias to point to and select "Make Alias"
  2. Move the alias to the Desktop and give it whatever name you want (using Finder)
  3. Assuming the icon you want to set is a PNG, open the image file in Preview and select Edit > Copy. This might work with many other image types too.
  4. Right-click the alias and choose Get Info, then click the icon in the top left, and in Finder's menu bar select Edit > Paste. This will paste the image in as the file's icon.

Now you have an alias that has a custom icon.

You must log in to answer this question.