简体   繁体   中英

Setting an icon for a symbolic link

I am trying to finish a product for a client and need to create two aliases on the Desktop and the Dock to make it easy for the end-user to start the two main apps in the product. The installation script finishes off the installation by setting icons to various folders and files. The installation creates a folder under the /Applications folder, and another under the /Users/Shared folder. Each of these folders has an icon applied to them using SetFileIcon (a shareware app). The script then creates two aliases on the desktop and applies an icon to each of these aliases, again using SetFileIcon.

My first problem is that one of the aliases points to an Excel spreadsheet, but this spreadsheet gets replaced each time the update application is run. This leaves the alias pointing to the spreadsheet in the wastebasket and the new file completely unaliased. My updater application is written in Mono - so there is no easy way to call out to the Mac OS to recreate the alias, reset the icon and put it on the desktop and the dock.

I tried to work around this by creating a symbolic alias to the spread sheet using the script command and then applying an icon:

SetFileIcon "/path/to/spreadsheeticonfile" "/path/to/spreadsheet.xls"
ln -s "/path/to/updater" "/Users/$USER/updateralias"
ln -s "/path/to/spreadsheet.xls" "/Users/$USER/spreadsheetalias"
SetFileIcon "/path/to/iconfile" "/Users/$USER/spreadsheetalias"

The first SetFileIcon command works fine, and the Spreadsheet now has a new Icon associated with it. The first "ln -s" also works fine, and a new slias is created with the updater icon associated with it. The second "ln -s" creates an alias to the spreadsheet, but there is a plain white icon, not the icon associated with the spreadsheet. The last SetFileIcon is my desparate attempt to force an icon on the alias - which also does not work.

I have tried creating a bash script that launches the excel spreadsheet, and that seems to accept an icon, but seems to have a similar . But it also leaves a terminal session running, after the excel spreadsheet starts, and the alias to the bash script will also not accept an icon, even when hand-applied.

2 questions: 1. Is there any way to assign an icon to a symbolic alias that works. Even hand setting the icon on the alias using GetInfo does not work. 2. Failing getting an Alias to work, is there any workaround that would allow me at installation time to have a link on the users desktop and their dock which has the nice icon we want to use, rather than a generic excel white square. I just need an easy way to put a link with an icon to a file in another directory on the user's desktop, which will survive that file being updated periodically, and do it at install time. Simple.

Suggestions welcome.

Thanks, Neil

PS It probably goes with out saying that I am a MAC newbie - I originally developed this product for the client in the PC World, but he then received repeated requests to translate it for the Mac, and so, here I am struggling to learn development on the Mac.

Symbolic links are not the same as aliases. (And there is no such thing as a "symbolic alias".) You cannot set the icon of a symbolic link, because it is not a normal file, and thus can't have the appropriate properties set on it.

There are a number of ways to create an alias, but one easy one is using AppleScript:

osascript -e 'tell application "Finder" to make new alias at (path to desktop folder) to (("/path/to/file") as POSIX file)'

(NB: The path will need to exist for this to work.)

Once you've done this, you should be able to set the icon on that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM