Setting an icon for a symbolic link - macos

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
P.S. 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.

Related

Creating Dropbox like DMG package

Does anyone suggest a freeware tool/script/manual_way of creating Dropbox like DMG -
Need to ask couple of questions --
I want double clicking the Folder-Icon should copy the folder(which would contain installer and uninstaller .app files of my application) into the system's /Applications folder.
Solution -- This has been solved using Applescript and changing icon of that applescript file to the folder-icon(i.e double clicking that script will move our folder(which would be present in a hidden folder) to /Applications.Any suggestions for second and third part?
Is it possible to show hyperlink of actual dropbox.com to actually open it's website?
And how we can customize volume's/Drive icon?
You can find a way to do it by reading this: Packaging a Mac OS X Application Using a DMG » asmaloney.com
I believe you can also use the trick of naming a shellscript file something.command in order to make it double clickable, (but maybe it will open the terminal, -I haven't tried it).

How Can I Change the Icon for an Existing Shortcut in shell script

I have installed my flash application using packagemaker installer. I have created short cut to desktop using shell Script. Now i want to change the default short cut Icon. Please tell me shell script to change the short cut icon.
MAC OS 10.7.2
Mac OS X doesn't have "shortcut files". It has either alias files or symbolic links (symlinks).
I imagine that you created a symlink, since you're working from a shell. Symlinks can't have custom icons. They have almost no real data or metadata of their own.
I don't know of a way to set an icon for an alias file (or any other file) from the shell. My first thought was AppleScript, which you can use from a shell via the osascript command. But I find that the Finder's AppleScript support does not include working with file icons. There's a definition of an icon family class, but it's marked as "NOT AVAILABLE YET".

open console (terminal) window and execute command (rsync) on os x

I am from a windows background and trying to help a mac user friend to backup her pictures, docs, etc. onto an external drive. In windows, I would accomplish this by creating a simple batch file with an xcopy command and have a shortcut on the desktop that pointed to that .bat file when double clicked. However, in the mac world I am having significant trouble finding how to do this. I have searched repeatedly to find the mac equivalent, but all I find are sites saying things like "there are so many options on a mac - use one of them." However, none have ever given a specific solution nor pointed to a specific solution. Anyone here know of a specific step by step process to accomplish this? I simply want to be able to have her double click an icon on the desktop and have it copy her personal documents (not application settings or other overhead) to her external hard drive. Any help would be appreciated.
Create the batch file, which is usually called a shell script.
Enter all the commands that you want to run.
Set the executable bit, this is done with chmod +x path-to-the-file in Terminal.
Show info for the script and set Terminal to the application which should open it.
However, what I've done in similar situations and that I would recommend that you do is that I've created a shell script and instead of using Terminal I've initiated it from an AppleScript application. You can of course embed the entire shell script in the AppleScript as well. Basically it will look something like the following:
on run
do shell script "rsync -av ~/Pictures /Volume/Backup"
end run
Repeat the do shell ... line for each folder that you want to copy, or call the shell script itself. Then use AppleScript Editor which is included with Mac OS X and save it as an actual application.

run applescript on 2x-click

OK, this feels like an idiot question, but I'm stuck - I don't know the first thing about AppleScript. I have a .scpt file and I want to double-click it and just have it run, but instead every time I click, it opens up the AppleScript Editor. This feels like it should just be an option on the file, but I'm missing something obvious.
Please help me feel less dumb, thank you.
From the “File” menu, choose “Export”; there’ll be a “File Format” dropdown underneath the file browser. To get a double-clickable application instead of a document, choose “Application”. This will produce a .app bundle like ordinary Mac applications (this will also let you package other resources with your script if you need to). You can choose “Run Only” or not; if you do, then anybody with just the .app won’t be able to edit your script further, since it’ll be compiled. (But if you’re saving a copy as the application, that might be what you want.)
Another option, as per an anonymous user on Ask Different, would be to save/export your file as a “Script” (.scpt) or “Script Bundle” (.scptd), save it in ~/Library/Scripts/, and check “Show Script menu in menu bar” in Script Editor’s preferences.
(If you’re running an old version of OS X, the first version of this answer has the information you’re looking for.)
There's more than one way to do it; i have found this to be the simplest:
In sum, you create an Automator application and place your applescript inside it (easier than it sounds, and it's not a hack either--there's actually a specific Automator action for this). Then when you are finished, you select "File" from the menubar, next "Save As Application", then select a location. Now check there and you'll see the newly-created Automator icon (little white robot holding a grenade launcher).
You can do anything that you would ordinarily do with this application icon--double click to open, drag it to your dock, etc.
Appstorm has created an excellent step-by-step tutorial for building an applescript-embedded automator action. On the page i linked to, the tutorial author has also supplied an Automator script that you can download and use as a template.
While it's certainly not the simplest route, one benefit to running your script from Automator, as doug suggested, is that you can set a hotkey or keyboard shortcut to execute your script if you hide it in an Automator Service (OSX 10.6+). See:
http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/
When you save a new script, a menu should appear asking what you want the file name to be, where it will be stored, any tags for it, and what script format you want it to be. There should be 4 scripts formats:
Script
Script Bundle
Application
Text
The script format you want to use would be "Application." This will turn it into a double-click application if its not in the dock.

Debugging a Cocoa droplet application in Xcode

When debugging in Xcode, how do I simulate a user starting my Cocoa droplet application by dropping one or more files onto it's application icon?
The app just opens, processes the files while displaying it's progress and then closes again.
Passing arguments (via the "Arguments" tab of the entry under "Executables") should allow this, but I could not find out how.
What I really want is to hit "Build and Go" and then have the droplet open with whatever files I need.
A last resort would be to use AppleScript or the "open" command on the command line to achieve this. I want to streamline this as much as possible.
Thanks for any pointers!
Add each absolute path to a file you want to open with the application as an argument. You may need to wrap each one in quotation marks (which shouldn't be necessary, and is a bug if it is, but I do remember needing to do).
You should be able to use variable references like $SRCROOT in order to refer to files within the project root directory.

Resources