Re: Testing for a specific value in a folder name
Re: Testing for a specific value in a folder name
- Subject: Re: Testing for a specific value in a folder name
- From: Axel Luttgens <email@hidden>
- Date: Wed, 05 Jul 2006 09:26:48 +0200
On 5/07/06 3:13, Brett Conlon wrote:
[...]
Here's what I have so far but the last line errors....
on run
set aFolder to choose folder
CheckDNum(aFolder)
end run
on CheckDNum(aFolder)
tell application "Finder"
set item_name to the name of aFolder as text
set AppleScript's text item delimiters to " "
set AllWords to every word of item_name as list
log AllWords
set Dnum to every word of AllWords whose character 1
is "D"
end tell
end CheckDNum
You already got lots of suggestions for working implementations.
If you allow, I'll just add some comments.
First, note that you could (should) have written your CheckDNum handler as:
-- Doesn't work either...
on CheckDNum(aFolder)
tell application "Finder" to set item_name to the name of aFolder
as text
set AppleScript's text item delimiters to " "
set AllWords to every text items of item_name as list
log AllWords
set Dnum to every item of AllWords whose character 1 is "D"
end CheckDNum
This shows that the Finder is only involved in getting the folder name
from the folder alias passed as an argument.
There are other ways to do it, but the important thing to note is that
the remainder of the handler is just pure AppleScript.
On the other hand, as you are setting the AppleScript's text item
delimiters for splitting a string into chunks, you have to as for the
string's "text items", not the string's "words".
It didn't matter in this precise case as, in most locales, spaces are
used to define words boundaries.
Now about the last line, the one that errors.
It uses what is called a "filter reference form" (one is filtering an
expression by means of logical conditions).
Such reference forms *may* be implemented by applications (and then in
very precise ways, application-dependant ways), but they aren't
implemented by AppleScript itself.
And we've just seen that the major part of your handler is just
targeting AppleScript.
Hence the failure.
HTH,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden