Re: Urgent Need help with Script!
Re: Urgent Need help with Script!
- Subject: Re: Urgent Need help with Script!
- From: email@hidden
- Date: Thu, 4 Jul 2002 14:42:04 EDT
Dan,
A few things are needed to correct the script you posted:
* the real action you plan to take involves moving items to the trash, so
you need the Finder to do that. Thus, you must first address the Finder
with "tell." ("list folder" is a command that derives from "File
commands" of the "Standard Additions" Scripting Addition. Therefore it
might be thought of as a "top level" command that, in essence, addresses
AppleScript itself, so it doesn't need to follow a "tell.")
* the other issue is one of proper referencing*. The result of "list
folder" is a list of names. What you need to pass to the Finder is either
aliases or file references. So you'll need to do something to turn the
filename back into something the Finder can reference.
Try this:
--- begin script
repeat with x in list folder (path to desktop folder)
if x is not in {"Macintosh HD", "Accel-a-Writer 3G Pool", "Launcher"}
then
tell application "Finder" to delete alias (((path to desktop folder)
as text) & x)
end if
end repeat
--- end script
The segment: "alias (((path to desktop folder) as text) & x)" is taking
two text strings (the path to desktop folder, which will have a ":" at
the end, and the filename of the current item from list folder), putting
them together (with "&") and adding "alias" to give the Finder what it
needs.
Some other things you might want to consider:
* The script we've just made will not work as expected if you have more
than one hard drive, since each disk has its own 'Desktop Folder.' This
script only affects the startup disk. (It's certainly possible to deal
with multiple disks, but maybe you don't need to.)
* there is a parameter for "list folder" that is often used as a safety
measure: "without invisibles." . . . . Maybe someone else can verify, but
I don't think it's relevant in your case, 'cause I understand invisible
files aren't stored on the desktop in any case.
( * This is a good reason to do your work in Script Editor with the
Event Log window open -- and check "Show Events" and "Show Event Results"
-- so you can see what AppleScript is doing at each step.)
HTH,
Dan Feather
-----It appears that email@hidden wrote, on 20020703 7:21
PM:
>
How can I make an
>
AppleScript to delete any other things on the Desktop if they are there? 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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-=- Dan at featherweightstuff dot com -=-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
_______________________________________________
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.