Re: Folder: alias:true/false property
Re: Folder: alias:true/false property
- Subject: Re: Folder: alias:true/false property
- From: Kai <email@hidden>
- Date: Tue, 18 Feb 2003 02:11:08 +0000
on Mon, 17 Feb 2003 03:41:12 +0100, Philippe GRUCHET
<email@hidden> wrote:
>
(Mac OS 10.2.4)
>
>
Subject: checking a disk for all alias found with true or false
>
property.
>
>
1) Problem: a folder (or an alias of it) has always 'alias:true' as
>
property.
Are you sure about a folder, Philippe?
OMM, 'info for' returns 'alias:true' only for aliases (of files or folders):
----------------------------------
choose folder [an original folder] --> {folder:true, alias:false}
choose file [an original file] --> {folder:false, alias:false}
choose folder [an alias of a folder] --> {folder:true, alias:false}
choose file [an alias of a file or a folder] --> {folder:false, alias:true}
----------------------------------
So the alias property merely confirms whether or not a selected item is an
alias (rather than if the alias is broken or not).
>
2) If the alias is broken, I always get this error message:
>
>
"The alias "foldername" could not be opened
>
because the original item cannot be found."
>
>
(Even if the compiled script is saved as applet, or launched from
>
"ScriptMenu".)
>
>
3) Of course, this routine doesn't work on a broken alias to a
>
(deleted) folder:
>
--================
>
tell application "Finder"
>
try
>
choose folder
>
set x to result
>
>
--> "Folder" in English, "Dossier" in French:, etc: localized!
>
>
if kind of x is "Alias" then return x --> non-sense, so:
>
on error
>
display dialog "Alias."
>
end try
>
end tell
>
--================
OMM, if an alias of a folder is chosen, 'choose folder' will try to resolve
the alias to the original folder. If the alias is broken, a dialog will
report the fact.
In your script above, the <display dialog "Alias."> command is invoked when
the user cancels 'choose folder'. So the try block traps an error number
-128 (user cancelled), rather than because an alias may be broken.
>
4) I don't understand how to handle this problem, only specific to
>
folder.
Well, specific to a broken alias selected with 'choose folder'.
>
Note: see first line below --> strange, folder must be set as a
>
litteral string. I don't know why: do you?
The line:
-----------------------------------------------
choose from list {application, file, "folder"}
-----------------------------------------------
...actually shows me a list like this:
------
capp
file
folder
------
That's because the 'choose from list' command is coercing 'application'
(<<class capp>>) and 'file' (<<class file>>) to "capp" and "file"
respectively.
Outside of a Finder tell block, the application keyword 'folder' is not
recognised. AppleScript tries to identify which folder is being referred to
- and errors when it can't get a specific folder.
This (sort of) works:
-----------------------------------------------
tell application "Finder" to set l to {application, file, folder}
choose from list l
-----------------------------------------------
...but (for similar reasons to those mentioned above) presents this list:
------
capp
file
cfol
------
I wouldn't generally recommend the use of classes in this way, since you may
end up with unpredictable results. (See below for an alternative method.)
>
This script works but displays the message above with no error number
>
reference to be handled:
>
>
--================
>
set chooseList to {application, file, "folder"}
>
>
choose from list chooseList as item --> display a dialog
>
set x to result as item
>
if false is x then return --> when user clicks Cancel
>
--
>
else if x is chooseList's item 3 then
>
try
>
set SelectedFolder to choose folder
>
if (info for SelectedFolder)'s folder is true then
>
display dialog "This is a folder."
>
end if
>
return
>
--
>
on error
>
display dialog "This is an alias."
>
end try
>
end if
>
--================
Although the above script doesn't go further than identifying a 'choose
folder' command, it looks as if you may ultimately be trying to do something
like this:
1) Use 'choose from list' to identify which type of item to choose
2) Use 'choose application', 'choose file' or 'choose folder' as specified
To do that, I'd probably try something like this instead:
==========================
set x to choose from list {"application", "file", "folder"}
if x is false then return
set y to (run script "choose " & x)
-- do something with y
==========================
However, none of that solves your ultimate problem:
>
5) Do you know a way to handle a broken folder's alias when the
>
original is not found (deleted), avoiding the AppleScript alert message?
If you try to use 'choose folder' on a broken alias, I can't see how you
could avoid the alert. You really need to check the alias before using
'choose folder'.
You suggested earlier that you want to check a disk for all aliases found
with true or false property. Do you mean you want to find broken aliases? If
so, there may be faster ways using OSAXen but - for a vanilla method - try
something like this:
======================
global brokenAliasList
to checkAliases from x
tell application "Finder" to [NO-BREAK]
set {aList, fList} to x's {alias files, folders}
repeat with a in aList
try
tell application "Finder" to a's original item
on error
set brokenAliasList's end to a as alias
end try
end repeat
repeat with f in fList
checkAliases from f
end repeat
end checkAliases
set brokenAliasList to {}
checkAliases from (choose folder)
-- do something with brokenAliasList
======================
This may take a while if you're checking an entire disk. Because it's a
recursive routine, it may also choke on many folders. But if this is the
sort of thing you're trying to do, it might just help you get started...
--
Kai
_______________________________________________
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.