Re: Finding folder from its id
Re: Finding folder from its id
- Subject: Re: Finding folder from its id
- From: Paul Berkowitz <email@hidden>
- Date: Sat, 23 Mar 2002 09:40:54 -0800
On 3/23/02 2:43 AM, "nick weldin" <email@hidden> wrote:
>
Is it possible to find the path to a folder in applescript given just its id.
>
I can find the id of a folder given its full path, and open a folder
>
using its id as long as it is on the desktop or just in the root of
>
the startup disk, but need to find the path to a folder that I have
>
the id for and could be saved anywhere on the startup disk.
>
Assuming you mean the Finder's id, this will work for folder or file:
tell application "Finder"
set thePath to ((the first item whose id = 31583) as alias) as string
end tell
Use 'folder' instead of 'item' if you want to restrict it to folders, and
put it in an error block in case the folder no longer exists. Frankly,
getting the path is just going to make more roundabouts for you. You'd be
better NOT to get the path but instead do something like this:
However, it's not going to work right. The classic Finder screws up again.
(It's always doing that.)
At least in OS 9.2.2, AppleScript 1.8.2b3, the Finder claims there's no such
folder when I move it off the desktop into another folder. If I then select
it there and get the id of item 1 of the selection, it gives me the correct
id. It just can't find it when I ask for it. Well, you could make THAT the
basis of an error trap, I suppose, but it would be totally unreliable. I
wouldn't. Yet another Finder bug. (The OS X Finder doesn't have the id
property for item, so no feature, no bug. You'd have to find another method
when you move there anyway.)
Instead, I would save the folder you want 'as alias' as a script property.
That will persist forever over script runs (until you recompile the script),
and you will be able to find the folder wherever it is, whatever its name,
unless it's been trashed. Then get its Finder container and check whether
it's the desktop or startup disk, like this:
property folderAlias: ""
if folderAlias = "" then
set folderAlias to choose folder with prompt "Select the folder for
future reference"
set folderPath to folderAlias as string
display dialog "OK. " & folderPath & " will be aved as alias." & return
& return & "Move it or rename it at will." buttons {"OK"} default button 1
with icon 1
return
end if
--quits after setting. On all future occasions:
try
tell application "Finder" to set theLocation to container of folderAlias
on error
beep
display dialog "The folder seems to have been trashed." buttons {"OK"}
default button 1 with icon 0
set folderAlias to "" -- reset script
return -- quit
end try
--we're OK
tell application "Finder"
if {theLocation} is in {desktop, startup disk} then
open folderAlias
else
set locationPath to (theLocation as alias) as string
beep
display dialog "The folder is buried in " & locationPath &" ." &
return & return & "Forget it." buttons {"OK"} default button 1 with icon 2
end if
--
Paul Berkowitz
_______________________________________________
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.