Re: can' t set path of original of alias file?
Re: can' t set path of original of alias file?
- Subject: Re: can' t set path of original of alias file?
- From: "Serge Belleudy-d'Espinose" <email@hidden>
- Date: Sun, 3 Mar 2002 15:28:29 +0100
At 1:10 -0500 3/03/02, Wayne Clodfelter wrote:
Hopefully the comments and script below are self explanatory. The script is
failing when I try to set the path of the original to which the alias
points, ie, point the alias at an identical original on the new disk.
As I understand it, you're trying to get the path of the original
item of an alias and then change this path so that the alias points
to a new item. With standard Finder commands this is simply
impossible. You cannot change the original, only get it. See the
entry in the Finder's dictionary for the alias:
Class alias file : (inherits from file) An alias file (created with
"Make Alias")
Plural form:
alias files
Properties:
original item reference [r/o] -- the original item pointed to
by the alias
r/o means the 'original item' property is read only.
Your script would have to lookup the original item of an alias, check
that the corresponding file exists on your new disk, and if so,
delete the alias and replace it with an alias to the 'new' item.
Here's your script revised.
Important note: while repeatedly testing the script I stumbled upon a
big problem. FindFile also lists aliases that are in the trash. So
the inital script would try to delete and update those aliases
already deleted. This, combined with a Finder bug, would make
_original items_ disapear, this is *extremely dangerous*!!! So I
added a condition so that the script only checks for aliases not in
the trash.
--------------------------------
set nameOfSourceFolder to "Seagate 2" -- name of the source disk
set nameOfOriginalDisk to "Macintosh:"
set lengthOfOriginalDisk to length of nameOfOriginalDisk
set theList to FindFile in_folder nameOfSourceFolder result_type
"TEXT" with kind_is_alias and subfolders
repeat with i from 1 to length of theList -- browse thru each item in theList
set tempPath to item i of theList
-- do not process aliases in the trash!
if tempPath does not start with (nameOfSourceFolder & "Trash") then
-- ask for the original item of the alias
-- error so do nothing if the alias is broken
try
tell application "Finder" to set pathOfOriginal to (original
item of alias tempPath) as string
if pathOfOriginal starts with nameOfOriginalDisk then
-- check that the equivalent item exists on the target disk
-- to do that, build a string by removing the name of the source disk
set pathOfTarget to text (lengthOfOriginalDisk + 1) thru end
of pathOfOriginal
-- and adding the name of the target disk
set pathOfTarget to nameOfSourceFolder & pathOfTarget
-- check the existence of the target item
-- the following will error if the item doesn't exist
try
set pathOfTarget to alias pathOfTarget
tell application "Finder"
-- now get the container folder of the alias and its name
set {tempName, tempContainer} to {name of item tempPath,
(container of item tempPath) as string}
-- trash the alias
move file tempPath to trash
-- in the container folder, make a new alias to the item
on the new disk
make new alias at folder tempContainer to pathOfTarget
with properties {name:tempName}
end tell
on error -- no existing target item, do nothing
end try
end if
on error -- broken alias, do nothing
end try
end if
end repeat
--------------------------------
Serge
--
\\//\//\// Serge Belleudy-d'Espinose Institut Jacques Monod - Jussieu
// // //
http://www.ijm.jussieu.fr/ Universites Paris VI, VII - CNRS
//\//\//\\
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.