Finder - Can't set original item of some alias - please help

Hey folks,

I ran into a somewhat strage problem and am completely stuck here.

I got an external HD with hundreds of raw files from a photo session and some folders with alias files which are personal selections from these photos. The alias files should point to the corresponding original raw files on the same disk, but eventually the complete contents of this disk has been moved from another HD to the one I got here - so all the alias files are “broken”.

I’m trying to relink them to the originals with a script that searches the corresponding folders for matching file names but Finder only gives me errrors.

Inside the loop that processes all the aliases this is the faulty part:


if exists orig_file_path_test then -- check if the assumed original file exists at the path contructed
	set current_alias_file to file this_alias_file_name of (alias_folder_path as alias)
  	set current_orig_file to file this_orig_file_name of (orig_folder_path as alias)
  	set original item of current_alias_file to current_orig_file
end if

The following error occurs:

Finder got an error: Can’t set original item of alias file “261_WBC B0034P 0720.fff” of folder “Peter K” of folder “CGW 2006 Auswahl” of disk “LACIE EXTERN” to document file “B0034P 0720.fff” of folder “RAW DATA 03” of folder “CGW 2006 Shooting” of disk “LACIE EXTERN”.

  1. “current_alias_file” is found by Finder
  2. “current_orig_file” is found by Finder
  3. “set original item of current_alias_file to current_orig_file” is the right term as I suppose

I don’t understand where I made a mistake…

Can you help?

Thank you very much!

Have you tried simply deleting the old alias file and creating a new one?

I think what adam means is some thing like this

tell application "Finder"
	set alias_folder_path to "Macintosh HD:Users:UserName:The:AliasFolder" as alias
	set orig_folder_path to "Macintosh HD:Users:UserName:New:file:folder:on:New:disk" as alias
	
	set alias_files to every file of alias_folder_path whose class is alias file as list
	repeat with i from 1 to number of items in alias_files
		set this_item to item i of alias_files
		set this_alias_file_name to displayed name of this_item
		
		if exists file this_alias_file_name of orig_folder_path then -- check if the assumed original file exists at the path contructed
			set current_alias_file to file this_alias_file_name of orig_folder_path as alias
			tell application "Finder"
				delete this_item
				make new alias file at folder alias_folder_path to current_alias_file
				
			end tell
		end if
	end repeat
end tell

Hehe, Adam… thanks. That worked… Sometimes I’m just to complicated in my thoughts and I just wanted that the command “set original item” worked. Still, I don’t know why it didn’t and I sure would like to know.

But this is a quite accaptable workaround… :slight_smile:


if exists orig_file_path_test then -- check if the assumed original file exists at the path contructed
	set current_alias_file to file this_alias_file_name of (alias_folder_path as alias)
	set current_orig_file to file this_orig_file_name of (orig_folder_path as alias)
	-- set original item of current_alias_file to current_orig_file -- <-- this didn't work
	move current_alias_file to trash
	set new_alias to make new alias file at folder (alias_folder_path as alias) to current_orig_file
	set name of new_alias to this_alias_file_name
end if

Thank you for your insight…

A note to mark: thank you too, but I did understand Adam quite well :wink:

I think your original script didn’t work because you didn’t tell the Finder to do it, but I haven’t played with that.

Although left out here in the thread, the complete part of the script had been within a TELL APPLICATION “FINDER” … “END TELL” statement.
I did this before and also tested this with some dummy files and aliases I created to recheck. It worked perfectly. Also on that external disk.

I have no idea, why it didn’t work within my script, though everything seems to be all right.

Is it possible that there is an issue with referencing files by name using plain text? I have had some problems localizing the correct original files by name comparison, because the alias names had been serialized and were not exactly the same as the names of the original files (like in “BDD 00134.fff” as original file name and “Peter Sel_02 BDD 00134.fff” as alias name). So I did some stripping on the alias file names which didn’t run very well in the first place because “BDD 00134.fff” (plain text) would not match any file name, not even “BDD 00134.fff” because it was returned as unicode text by the finder…

Am I confusing you? :wink: sorry!

Maybe you’ve found an AppleScript bug. The reason seems to be that it is simply impossible to set the ‘original’ item when the alias is broken. I’ve tried this (using a non broken alias):

set a to choose file with prompt "select alias"
set b to choose file with prompt "select new original item (will be deleted!)"
set posixB to (quoted form of POSIX path of b)
set c to choose file with prompt "select an second original item"

tell application "Finder"
	set original item of a to b
	reveal (get original item of a)
	display dialog "first original item worked - now I remove it and try to set the second file as original item ..."
	do shell script "rm " & posixB
	try
		set original item of a to c
	on error errMsg
		display dialog errMsg
	end try
	
end tell

Important note: The first file you select as new original item will be removed to create the broken alias!

D.

Thanks for your testing! Yes, it seems that you are right.

It’s sad, but as the workaround does it’s job, I get along with it and know what to do in the future…