Strange work Aliases, why?

Save the script as the application and execute actions:
1.Create file ScriptName.Cfg
2.Move to tmp folder
3.Run ScriptName.app
4.New Button --Creating file ScriptName.Cfg
5.Move ScriptName.Cfg to folder tmp1
6.Run ScriptName.app --show new location of ScriptName.Cfg
7.move ScriptName.Cfg of tmp folder to ScriptName.app location
8.Run ScriptName.app --show Cfg file in location of ScriptName.app ???
–No alias assigned ScriptName.Cfg of tmp1 :frowning:

N2
1.Create file ScriptName.Cfg and move to Trash
2.Run ScriptName.app
3.New Button --Creating file ScriptName.Cfg
4.Run ScriptName.app–show location of ScriptName.Cfg
5.Move ScriptName.Cfg to Trash
6.Run ScriptName.app–show location of ScriptName Copy.Cfg
7.UnDelete ScriptName.Cfg to location of ScriptName.app
8.Run ScriptName.app–show location of ScriptName.Cfg???
9.UnDelete ScriptName Copy.Cfg to location of ScriptName.app
10.Run ScriptName.app–show location of ScriptName.Cfg
11.Rename ScriptName.Cfg to ScriptNameTMP.Cfg
12.Run ScriptName.app–show location of ScriptName Copy.Cfg!!!
Why?

on TextItemElement(dta, razdelitel, counter)
	set AppleScript's text item delimiters to razdelitel
	set stroka to (text item counter of dta) as string
	return stroka
end TextItemElement

on ExchangeExt(fle_full_name, ext)
	set old_delim to AppleScript's text item delimiters
	set verbose_ext to TextItemElement(fle_full_name, ".", -1) of me
	if (count verbose_ext) < (count TextItemElement(fle_full_name, ":", -1) of me) then
		repeat while ((last character of fle_full_name) is not ".")
			set fle_full_name to text 1 thru -2 of fle_full_name
		end repeat
		set fle_full_name to fle_full_name & ext
	else
		set fle_full_name to fle_full_name & "." & ext
	end if
	set AppleScript's text item delimiters to old_delim
	return fle_full_name
end ExchangeExt

property fle : ExchangeExt(path to me as text, "Cfg") of me

tell application "Finder"
	if (class of fle) is alias then if not (file (fle as text) exists) then set fle to ExchangeExt(path to me as text, "Cfg") of me
	
	if file fle exists then
		set fle to fle as alias
		display dialog "Present!" & (fle as text)
	else
		set knopa to button returned of (display dialog "Create text file of word?" buttons {"New", "Open"} default button 2)
		if knopa is "Open" then
			set fle to choose file
		else
			set my_name to name of file (path to me)
			set fle to (make new file at (folder of (path to me)) with properties {name:(ExchangeExt(my_name, "Cfg") of me)}) as alias
		end if
	end if
end tell

Hi KIA,

It’s very hard to decipher your post. Still trying to figure out what the question is, although I think I’m getting close. It would help if you posted a simple example of what you’re trying to do, and say exactly what’s happening, and ask a clear question. Maybe somebody else understands this post? Something about an alias reference I think.

gl,

I agree, kel. Spent several minutes and then abandonned it.

Alias should specify the same file even if a file to move to other folder or to rename. In an example Alias changes the value (specifies other file at performance of actions) at change of a name of a file or moving. How it is reliable to appropriate Alias to a file?

It is a question of internal representation Alias in AppleScript, instead of file Alias on HDD.

I’m still not sure of your problem KIA.

This works for me:


set F to alias ((path to desktop as text) & "Test")
set fld to alias ((path to desktop as text) & "TestF:")

tell application "Finder"
	move F to folder fld
	set name of F to "Test2"
end tell

tell application "BBEdit" to open F

Tell us what doesn’t work for you. Are you, for example, moving the file to another volume?

No, I did not move a file to other volume. Create in my program a file, it will specify Alias. Move this file somewhere. Custom create on an old place the same file. Alias begins to specify last created, having lost that has been move.

Save the script as the application (MyProgram) and execute actions:
1.Custom Create file MyProgram.Cfg
2.Move MyProgram.Cfg to tmp folder
3.Run MyProgram.app
4.Pressed New Button --This is Create file MyProgram.Cfg
5.Move MyProgram.Cfg (NewCreated) to folder tmp1
6.Run MyProgram.app --show new location (tmp1) of MyProgram.Cfg
7.move MyProgram.Cfg of tmp folder to MyProgram.app location
8.Run MyProgram.app --show Cfg file in location of MyProgram.app ???
–No alias assigned MyProgram.Cfg of tmp1

Hello

My guess is that you fail to make a difference between

alias used as a class of objects (“my:beautiful:file” as alias)

and

alias used as a kind of pointer to a file. (“Idle_skeleton.scpt alias” (with a curved arrow at left bottom) is an alias of the file “Idle_skeleton.scpt”.) It is true that normally this kind of alias is adjusted when the parent file is moved.

Yvan KOENIG (from FRANCE lundi 22 janvier 2007 16:53:16)

Now I understand.

Here is my test, and I get the same result. I did not know that would be the case.


set F to alias ((path to desktop as text) & "Test")
set fld to alias ((path to desktop as text) & "TestF:")

tell application "Finder"
	move F to folder fld
	set name of F to "Test2"
end tell

set N to open for access ((path to desktop as text) & "Test")
close access N

tell application "BBEdit" to open F -- opens the new version.
-- i.e. The alias now points to the copy with the original name.

My guess is that the script attempts to resolve the alias using the original definition. If that works, it opens that file. If it doesn’t, then it looks for the same document number and opens that. I’ve written to the applescript list to see what they say about it.

Hello

If you are working with “alias files”, it would be useful to read what the Finder’s dictionary contains:

alias file‚n [inh. file > item] : every alias file
elements
contained by application, containers, disks, folders, desktop-objects, trash-objects.
properties
original item (reference) : the original item pointed to by the alias

When I work with such file, I always ask for the “original item” because it seems that some apps doesn’t work reliably with the automatic processing.

Yvan KOENIG (from FRANCE lundi 22 janvier 2007 18:22:34)

Hi,

Now I see it also. Here’s the example I used with just folders:


set target_folder to choose folder
set n to name of (info for target_folder)
set main_folder to choose folder
set dest_folder to choose folder
tell application "Finder"
	move target_folder to dest_folder
	make new folder at main_folder with properties {name:n}
end tell
display dialog (target_folder as string)

I guess people hardly ever use the same name when creating new items. After the ‘move’, store the reference as string would save the moved item’s reference.

gl,

Here’s a better workaround. From the example, I create a new alias reference by corcing to string and alias reference.


property moved_items : {}
--
set main_folder to choose folder
set dest_folder to choose folder
set target_folder to choose folder
set n to name of (info for target_folder)
tell application "Finder"
	set target_folder to ((move target_folder to dest_folder) as string) as alias
	make new folder at main_folder with properties {name:n}
end tell
target_folder

Edited: wait you don’t need al the coercions. Just resetting the variable to the return is enough:


property moved_items : {}
--
set main_folder to choose folder
set dest_folder to choose folder
set target_folder to choose folder
set n to name of (info for target_folder)
tell application "Finder"
	set target_folder to (move target_folder to dest_folder) as alias
	make new folder at main_folder with properties {name:n}
end tell
target_folder

gl,

Reproduce actions number two. Right at the end renaming ScriptName.Cfg in ScriptNameTMP.Cfg the program transfers index Alias on MODIFIED name ScriptName Copy. Cfg. I think, that all is much more complex. In my program I use stock-taking a file through the text form. It is necessary because " if file alias exists " will give out a mistake in case of physical absence of a file and the condition will not be fulfilled.

N2
1.Create file ScriptName.Cfg and move to Trash
2.Run ScriptName.app
3.New Button --Creating file ScriptName.Cfg
4.Run ScriptName.app–show location of ScriptName.Cfg
5.Move ScriptName.Cfg to Trash
6.Run ScriptName.app–show location of ScriptName Copy.Cfg
7.UnDelete ScriptName.Cfg to location of ScriptName.app
8.Run ScriptName.app–show location of ScriptName.Cfg???
9.UnDelete ScriptName Copy.Cfg to location of ScriptName.app
10.Run ScriptName.app–show location of ScriptName.Cfg
11.Rename ScriptName.Cfg to ScriptNameTMP.Cfg
12.Run ScriptName.app–show location of ScriptName Copy.Cfg!!!

In the problem I need to make, that the configuration file would be in any place and with any name at various times, and in case of its physical destruction was created or got out new: at the choice of the user. For a finding of the moved or renamed file it is possible to use only Alias as there is no other opportunity to watch actions of the user after closing the program.
Thus presence of any a configuration file in a place, stipulated by default, should not cancel communication with the config chosen initially.

Hi, guys.

This issue is probably down to the way in which the Alias Manager now tries to resolve a file path name before attempting to resolve the alias using the file id. I believe the behaviour was introduced in Mac OS X 10.2, to correct a problem with aliases not working as expected on volumes restored from a back up.

This is a tough one. Aliai are too smart for their own good.