Re: Questions questions...
Re: Questions questions...
- Subject: Re: Questions questions...
- From: Kai Edwards <email@hidden>
- Date: Tue, 12 Mar 2002 00:57:07 +0000
on Mon, 11 Mar 2002 15:19:50 -0600, mjn <email@hidden> wrote:
>
I am attempting to write a script which will look at all of the files in
>
Startup items and delete any file whose creator matches "NDS".
>
>
I wrote something like this:
>
>
on run
>
tell application "Finder"
>
activate
>
set theFolder to startup items folder
>
set fileNames to (every item whose file creator contains "NDS") of
>
theFolder as list
>
repeat with myFile in fileNames
>
set delFile to (theFolder as string) & contents of myFile
>
delete delFile
>
end repeat
>
end tell
>
end run
>
>
But I keep getting errors about not being able to turn some things into
>
items or other things into strings.
>
>
Suggestions? Is there something blatantly stupid I have done here? Seems
>
to me this should be a bunch easier than it actually is...
No, nothing stupid there at all, mjn.
But a few points and refinements should help to make it a bunch easier (and
simpler):
1) It's not essential to activate the Finder to make this script work.
2) The term 'file creator' is a property label from a record returned from
the scripting addition command 'info for'. With the Finder, you'd be better
off using the term 'creator type' instead.
3) When you get 'items', a list should be returned anyway - so the coercion
"...as list" shouldn't really be necessary.
4) Since the Finder should be able to delete an entire list of files, you
might be able to do the job without even using a repeat loop.
5) Any files in listed in this way normally include their full paths - so
trying to concatenate them with "(theFolder as string)" could be causing
problems.
6) The "contents of myFile" is just returning the same as "myFile" here, so
it's not really helping any.
7) It's not always necessary to store every value in a variable. You can
sometimes issue commands directly. (See the example below.)
8) Finally, the 'creator type' property is normally a four-character code
(including spaces - which can sometimes be overlooked). Since you're
deleting files, it might be safer to use the forms <= "ABCD"> or <is "ABCD">
- rather than the less specific <contains "ABC">.
Taking all those points into account, you might even be able to simplify the
whole operation into a single line. I tried throwing a few SimpleText files
into my Startup Items folder and found that this worked for me:
tell application "Finder" to delete [NO BREAK]
(startup items folder's items whose creator type = "ttxt")
Sorry to subject you to a rather long-winded answer, but I hope you find it
helpful.
Best wishes.
Kai
--
**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************
_______________________________________________
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.