Re: Urgent Need help with Script!
Re: Urgent Need help with Script!
- Subject: Re: Urgent Need help with Script!
- From: Nigel Garvey <email@hidden>
- Date: Thu, 4 Jul 2002 16:14:34 +0100
Dan Ball wrote on Wed, 03 Jul 2002 20:21:49 -0400:
>
.... The only things that should be on the Desktop are
>
Macintosh HD, Accel-a-Writer 3G Pool, and the launcher. How can I make an
>
AppleScript to delete any other things on the Desktop if they are there?
tell application "Finder" to delete (items of desktop whose name is not
in {"Macintosh HD", "Accel-a-Writer 3G Pool", "Trash"})
The above is all one line. It doesn't mention the Launcher because that's
not a desktop item. It does mention the Trash because otherwise the
attempt to delete it would cause the script to fail. (I don't actually
know what "Accel-a-Writer 3G Pool" is.) It's a "hard wired" script which
assumes that your startup disk is called "Macintosh HD", that you have no
other volumes mounted, and that the Trash is so called in your
localisation of the Finder. It doesn't even *consider* desktop printers.
For my own use - with one machine running British English 8.6 and another
running "International" English 9.2.1, both machines having RAM disks,
and both having had their startup disks renamed to avoid confusion when
they're networked together - I'd generalise the script to something like
this:
set exclusions to (list disks) & "Accel-a-Writer 3G Pool"
tell application "Finder"
set exclusions to exclusions & name of trash
delete (items of desktop whose name is not in exclusions)
end tell
>
I
>
had some help before but they couldn't get it to work, here is the script
>
that was send to me:
>
>
repeat with x in list folder (path to desktop folder)
>
if name of x is not in {"Macintosh HD", "Accel-a-Writer 3G Pool",
>
"Launcher"} then move x to trash
>
end repeat
>
>
Looks like it should work but I'm not sure about the (path to desktop
>
folder) is that supposed to be worded like that or am I supposed to type in
>
the path to the desktop folder?
'list folder (path to desktop folder)' is a perfectly good expression,
being a combination of two of the Standard Additions commands. 'path to
desktop folder' (or just 'path to desktop') returns an alias and 'list
folder' uses that as its parameter. The first problem with your script is
that 'list folder' only returns a list of *names*, not of aliases. You
can't get the name of a name and you can't move a name to the trash.
Secondly, 'list folder' doesn't return the names of disks, the trash, or
(as I mentioned above) the Launcher. However, it does return the names of
invisible items unless you tell it not to. You won't want to delete
these. (You can't anyway with the Finder.) Finally, it's the Finder that
gets the names of items and moves items to the trash, so those
instructions should be addressed to the Finder in a 'tell' block.
A working version of your script would be:
repeat with x in (list folder (path to desktop folder) without
invisibles)
if contents of x is not "Accel-a-Writer 3G Pool" then
tell application "Finder"
move item (contents of x) of desktop to trash
end tell
end if
end repeat
... but it's comparatively slow.
NG
_______________________________________________
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.