Replacing an Alias with the Original Item

Hello,

I have a large library of original files and documents that I use for lectures and presentations. I make separate folders for each lecture and fill them with aliases of the originals I need for that specific lecture. I often change the name of the alias for sorting purposes, and there may be the occasional alias of an alias.

Sometimes, however, I need to replace an alias with a copy of its original, so that I can customize that file for the particular lecture it’s being used for.

More generally, I would like to be able to do more with aliases than is built in to the Finder. I have found one or two apps that approach what I would like, but either they involve dialog boxes and navigation to the location of the original file, or they only process folders, not individual files. I would like a droplet or script that would immediately replace a selected alias (or aliases) with a copy of its original without any “mucky-muck.”

In fact, if it’s not too much to ask, I would like to be able to do the following actions (via a separate script for each):

  1. Replace selected alias(es) with duplicate(s) of the original item.
  2. Replace selected alias(es) with duplicate(s) of the original item, with option to keep alias’ name or use original’s name if file names differ.
  3. Replace selected alias(es) with original file (i.e., move original item(s) to location of selected alias(es)).
  4. Replace selected alias(es) with original file (i.e., move original item(s) to location of selected alias(es)) with option to keep alias’ name or use original’s name if file names differ.
  5. Find all aliases of a selected original item, including aliases with changed names.
  6. Delete all aliases of a selected original item, including aliases with changed names.

I don’t know if these last two are possible for AS or anything else. (Did I mention that I’m a noobie to scripting?) I imagine that items 1 and 2, or 3 and 4 could be combined so that the naming option would appear only when any file names actually do differ. And I suppose some sort of warning confirmation might be in order: “Really replace all aliases with copies of original items?” but I could do without it.

Hope this all makes sense. Thanks for any help.

gasparschott

Model: MacBook Pro core duo
Browser: Firefox 3.5
Operating System: Mac OS X (10.4)

This will get you started. It accomplishes task #1. It should teach you how to get selected files, use a repeat loop so you can act on those files, find information out about the files, trash files, and duplicate files. You can use this knowledge to attempt the other tasks.

tell application "Finder"
	set theSelection to selection -- get the selected files in the front finder window
	repeat with aFile in theSelection -- loop through the selected files
		if class of aFile is alias file then -- make sure we are working with an alias file
			set originalFile to original item of aFile -- the original file of the alias
			set containerFolder to container of aFile -- container folder of alias
			move aFile to trash -- delete the alias
			duplicate originalFile to containerFolder -- duplicate original to container folder
		end if
	end repeat
end tell

Thanks so much! This does exactly what I want it to do, as a beginning. I’ll try my hand at adding the additional functions, like the naming options and warnings; I’ll be sure to post my questions here.

I’d still like to know if it is possible to easily find all the aliases of a given original item, however. I fear it would involve a complete search of all files on the drive, which wouldn’t be very quick. In other words, since (I assume) there is no central database of aliases, and since making an alias doesn’t change anything in the original item, the only way to find the aliases of a selected item is to search every other alias’ resource fork. Am I right?