Skip navigation
This discussion is archived

Tell me whats wrong with this script

609 Views 4 Replies Latest reply: Oct 17, 2008 3:25 PM by Niel RSS
BenChase Level 1 Level 1 (10 points)
Currently Being Moderated
Oct 17, 2008 1:35 PM
I am trying to check the first part of a file name and if it doesn't have the right begginning then I want to move it to another folder. The problem is that its not checking past the first "RepCode" in the list

tell application "Finder"
set FileName to item 1 in folder "OutFolder:Out" as text
set RepCode to items 19 thru 21 in FileName as text
try
if RepCode is not "A10" or "A11" or "A12" or "A13" or "A14" or "A15" or "A16" or "A20" or "A22" or "A23" or "A26" or "A30" or "C33" or "C34" or "C40" or "C41" or "C42" or "C44" then move FileName to folder "OutFolder::No Rep Code"
end try
end tell

why wont this work?
  • Niel Level 10 Level 10 (234,855 points)
    Currently Being Moderated
    Oct 17, 2008 1:45 PM (in response to BenChase)
    Use the following:

    if RepCode is not in {"A10", "A11", "A12", "A13", "A14", "A15", "A16", "A20", "A22", "A23", "A26", "A30", "C33", "C34", "C40", "C41", "C42", "C44"} then move FileName to folder "OutFolder:No Rep Code"

    (36622)
    iMac Late 2007 Core 2 Duo, Mac OS X (10.5.5)
  • Camelot Level 8 Level 8 (45,670 points)
    Currently Being Moderated
    Oct 17, 2008 2:13 PM (in response to BenChase)
    Just so you understand why your original code fails, you need to understand how the 'if' statement works with or conditions.

    Each 'or' separates different test conditions. Therefore your statement:

    if RepCode is not "A10" or "A11" or "A12" or "A13" then...


    (condensed for illustration) can be read as:

    if (RepCode is not "A10") or ("A11") or ("A12") or ("A13")...


    Each parentheses condition needs to stand alone as a valid true/false condition, so your first check sees if RepCode is not "A10" then it checks if "A11" is true - there's no relationship between RepCode and A11 since they're two separate conditions.

    The first way to change this is in the form:

    if (RepCode is not "A10") and (RepCode is not "A11") and (RepCode is not "A12") and (RepCode is not "A13")...


    but clearly that gets very verbose, hence Neil's suggestion to use a list and see if RepCode is in the list.
    Note also the switch to using and rather than or since you want all the conditions to be true (RepCode doesn't match ANY of the values), otherwise it will return true if it matches ANY.
    Mac OS X (10.5.4)
  • Niel Level 10 Level 10 (234,855 points)
    Currently Being Moderated
    Oct 17, 2008 3:25 PM (in response to BenChase)
    Here:

    if RepCode is not in {"A10", "A11", "A12", "A13", "A14", "A15", "A16", "C44"} then
    set RepCode to NoRepCode
    move FileName to folder "Current Art:Proofs Out:No Rep Code" with replacing
    end if

    A full if block is needed if you want to execute more than one command.

    (36630)
    iMac Late 2007 Core 2 Duo, Mac OS X (10.5.5)

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.