Re: Desktop question
Re: Desktop question
- Subject: Re: Desktop question
- From: Richard 23 <email@hidden>
- Date: Wed, 24 Jan 2001 11:20:51 -0800
>
tell application "Finder"
>
set name of file "Temp" of folder "Desktop Folder" of disk "MyDisk" to
>
"Perm"
>
end tell
Maybe it's just a style issue, but I find it much easier to work with (and
read) scripts using the alias-path paradigm rather than a Finder
reference.
tell application "Finder"
set name of file "MyDisk:Desktop Folder:Temp" to "Perm"
end tell
>
It yields the same error message you got (with the different names).
>
The Mac OS 9.1 Technote indicates that the Finder was fixed so it now always
>
determines the volume on which a desktop folder resides on the fly (as I
>
understand it), rather than making assumptions.
Well it's about time! I have always partitioned my drives, originally to
make switching between systems easier and also because defragmenting was
faster and more convenient. I seem to remember Norton's Speed Disk taking
as much as an hour to optimize the 500mb drive on my old 660av.
So I have always scripted defensively with regards to multiple volumes and
the desktop. All the way up to AppleScript 1.4.3 (Mac OS 9.0.4) coercing
directly to string a file reference pointing to a desktop file not
contained
by the startup volume always returned the startup volume in the path.
So you're saying this is no longer the case? I will continue to use
theFile as alias as string
to ensure backward compatibility but am glad if indeed this has been
fixed.
>
The bug you have discovered (and older bugs relating to the Desktop Folder
>
that persist in the Finder's AppleScript implementation) suggest to me that
>
Finder scripting might not have caught up with this change to the Finder's
>
inner mechanisms.
I'll have to read the technote (still haven't had time to "upgrade" yet).
This sounds like a contradiction. If the Finder doesn't determine the
volume on which a desktop folder is contained then under what conditions
does this bug fix manifest itself? It's my understanding that if you
have a file reference (as opposed to a file specification) any coercion,
such as to a path string would use the Finder even when the coercion is
performed outside of a Finder tell block. Maybe you can clarify?
>
I have already noted that various AppleScript constructs report that files
>
dragged to the desktop from non-startup disks still report that they reside
>
on the startup disk.
Oh, well in that case I definately will continue to use the "as alias as
string" method to get a path string. It seems the fix isn't really very
effective since it only works in an as yet unspecified context.
>
However, it isn't necessary to specify that the disk is in a Desktop Folder
>
folder. This script works:
>
tell application "Finder"
>
set name of file "Temp" of disk "MyDisk" to "Perm"
>
end tell
Maybe this time but I wouldn't rely on that method. Not a good idea.
It's best to go the defensive route. Although not very likely, if there
are two items on the desktop with the same name (but are from different
volumes) this method will get the startup volume's item even if the item
is from another volume. This becomes more likely with "Untitled Folder"
because people often create a temp folder and drag it to the desktop.
Debugging scripts which handle this incorrectly can be a frustrating
experience, especially if you don't know what you're looking for.
My general rule (and it's consistently applied in all of my scripts
beginning around 1995-96?) is that if there's any possibility that a
variable may contain a refence to a desktop file on a multiple volume
system (which is pretty much always) I make sure that when getting
the path to the file as a string I always coerce to an alias first.
I'm sure you already know most of the "gotchas" but:
-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d2
-- ---------------------------------------------------------
-- I created two new folders one in the startup disk ("Private")
-- and the other from another volume ("Netweb") and moved both to
-- the desktop. Both are selected in the Finder for the following:
tell application "Finder"
-- gotcha #1: improper coercion of Finder references
set {ItemOne, ItemTwo} to selection
{itemOne as alias, itemTwo as alias}
--> {alias "Private:Desktop Folder:untitled folder:", ==>
alias "Private:Desktop Folder:untitled folder:"}
-- solution: coerce to aliases before assigning to variables
-- of course alias list has its own problems, hence,
-- gotcha #2: alias list generates error if only single item,
-- and fails completely with a list of Finder references*.
-- I'll show the Finder reference failure first.
set {ItemOne, ItemTwo} to selection
{ItemOne, ItemTwo} as alias list
--> {folder "untitled folder", folder "untitled folder"}
-- solution: handle the exception for the single item
-- if your editor can't handle "compound block statements"
-- you'll need to separate the tell and try into two blocks
tell selection to try
it as alias list
on error
it as alias as list
end try
set {itemOne, itemTwo} to result
--> {alias "Private:Desktop Folder:untitled folder:", ==>
alias "Netweb:Desktop Folder:untitled folder:"}
-- ---------------------------------------------------------
*the solution for the "list of Finder references to alias list
failure" is more complex than I would like to go into here.
If you have experienced this problem or want to be prepared
lest it catch you off-guard, a fix and documentation is here:
<
http://homepage.mac.com/richard23/applescript01.html#AliasList
If you have questions about this, feel free to send an email.
A script which only deals in aliases (eg, the open handler,
choose folder, choose file, etc) should be fine. But any
Finder reference --> string coercions without first coercing
to an alias may have problems on a multi-volume system.
An example of a script which consistently handles the desktop
pitfalls is my DesktopDropper droplet, which moves items dropped
to it to an appropriate temp folder on the desktop (one for each
volume). It's primary mission is to prevent the annoying copy
that occurs if you accidentally drop a desktop file to a folder
from another volume. Coincidentally, DeskDropper is located at:
<
http://homepage.mac.com/richard23/applescript02.html#DeskDropper>
If you've got time to kill, sit back, kick off your pants and
go One Step Beyond. There's a number of "useful" scripts in the
land beyond...
Note: A major update to the site is still not ready after a month
of working on it...but it's really close. The update deals mostly
with the underlying JavaScript/JSCRIPT/EcmaScript, but I also am
Implementing HTML4.01 & DOM compliance for Netscape6/Mozilla,
DOM gymnastics for Nav4 and IE, very defensive stylesheets as
usual for the poor Nav4 css implementation and dumbed down
JavaScript [JSCRIPT] where necessary for IE). I won't rest until
my site is equally repulsive in all major browsers!
Once iCab finally gets CSS-1 implemented, iCab users will also
feel the full impact head-on. Adding better support for the
rebellious users of text-only browsers as well.
Phooey!
R23