Re: What does "Finder could not get folder..." mean? (tell block abuse)
Re: What does "Finder could not get folder..." mean? (tell block abuse)
- Subject: Re: What does "Finder could not get folder..." mean? (tell block abuse)
- From: Frank Miedreich <email@hidden>
- Date: Thu, 2 Aug 2001 05:59:39 +0200
At 18:12 Uhr -0500 01.08.2001, JollyRoger wrote:
On 8/1/2001 1:44 PM, "Chris Page" <email@hidden> wrote:
nigh on 8/1/01 10:08 AM, JollyRoger at email@hidden wrote:
On 8/1/2001 8:06 AM, "Chris Page" <email@hidden> wrote:
set pathList to pathList & (" '" & l & "'")
^^^
It happens here. This sends a "get" event to the Finder, which returns the
error.
The question is: Why are you telling the Finder to set pathList
to pathList
& (" '" & l & "'")? There are zero Finder commands in that line. You are
causing the error by getting the Finder involved in something in which it
has no business being involved. As a matter of fact, there are many lines
in the script that have zero Finder commands in them; yet they are all
enclosed in a Finder tell block. Why?
Well, like I said, that line sends a "get" to the Finder, because there's an
implicit "get i as alias"
No, it is sent to the Finder because you enclosed the command in a Finder
tell block - no other reason. Remove the tell application "Finder" from the
command and the Finder will stop trying to interpret the command.
(in fact, I tried doing it explicitly and the problem seemed to go
away for a
bit, but then it came back).
It's not magic. You must have changed something to make it break again.
I'd need more specifics to tell you what you did wrong.
Maybe that doesn't require a tell block,
Not maybe - definitely. None of the commands in that line are Finder
commands - and that goes for all but one line of the entire script.
but anyway I don't think the use of a tell block is the problem. Are you
saying that it *is* the problem or you just think it *could* be the problem?
The Finder is generating an error because it is trying to make sense of the
command. The command isn't a Finder command. If you weren't sending the
command to the Finder in the first place, you wouldn't be having this
problem.
This is what I mean by tell block abuse. The bad habit of enclosing
everything in tell blocks cause this and other subtle problems that are hard
to diagnose. You can save yourself some time and trouble by using better
judgment when choosing to use tell blocks.
Hi,
while I agree with the general idea about being careful with the tell
blocks, IMHO this is not relevant here. A quick look at the
appleevents protocol will tell you that the tell block will extend
around the repeat loop in both versions:
version a)
tell application "Finder" to set lockedFiles to get every file of
folder "System:test" whose locked is true as list
if the length of lockedFiles is greater than 0 then
set pathList to ""
repeat with l in lockedFiles
set pathList to pathList & (" '" & l & "'")
end repeat
end if
display dialog pathList
version b)
tell application "Finder"
set lockedFiles to get every file of folder "System:test"
whose locked is true as list
if the length of lockedFiles is greater than 0 then
set pathList to ""
repeat with l in lockedFiles
set pathList to pathList & (" '" & l & "'")
end repeat
end if
end tell
display dialog pathList
The eventlog is identical in both cases:
Eventlog:
Script "script" started
tell application "Finder"
get every file of folder "System:test" whose locked = {
true
}
--> {
file "6606.tkf" of folder "test" of startup disk
}
get file "6606.tkf" of folder "test" of startup disk
--> "System:test:6606.tkf"
end tell
tell current application
display dialog " 'System:test:6606.tkf'"
--> {
button returned:"OK"
}
end tell
Script "script" finished
This is also true if you make an explicit tell block with an end tell
in version a.
I think reason is that the line "set pathList to pathList & ..."
needs to be executed by the finder as the list items are files. In a
string context Applescript needs to transform the file objects to
string representations, the Finder can do that by delivering the path
to the file. So Applescript will extend the tell block, regardless of
where you put end tell.
Note that the script works without any problem for me, on a German OS
9.1 with Applescript 1.6.
To solve the problem I would check the version of Applescript, and
make sure that the filesystem is ok. The code should definitely work,
at least I did not have any problems. BTW, if this is not part of a
larger problem, and you really just need to unset the locked of the
files, this should also work:
tell application "Finder" to set locked of every file of folder
"System:test" whose locked is true to false
cheers, Frank
--