Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Condition Rule ignored?

I can't work this out but for some reason I can get it to see this rule



When it gets to

ifthisBrandisequal to "Kids" then

it seams to ignore it?


I can't see where the logic goes wrong?


This was the outcome


tell application "Mail"


makenewoutgoing messagewith properties {subject:"Week 33 images", visible:false}


--> outgoing messageid 1


(*Kids*)


display dialog "2"




Thanks in advance!




tell application "Mail" to quit


--while mail is closed, add in the default Reply-To key in a UserHeaders dictionary

do shell script "defaults write com.apple.mail UserHeaders '{\"Reply-To\" = \"me@company.com, you@@company.com\"; }'"


display dialog "Please enter the current week number." default answer ""

set weekNumber to text returned of the result


set brandsToUse to choose from list {"Adult", "Kids", "Baby"} with prompt "Choose brands to send out." default items {"Kids"} with multiple selections allowed



-- get the html template


set htmlTemplate to read "Users/StudioD/WorkFlow/EMAIL PROJECT/content.html"

considering case


-- this section splits the template text at every XX, then rejoins it using the week number

set htmlTemplate to tid(htmlTemplate, "XX")

set htmlTemplate to tid(htmlTemplate, weekNumber)

end considering


tell application "Mail"

set subjectLine to "Week " & weekNumber & " images"


repeat with thisBrand in brandsToUse

considering case


-- this section adds the brand name, done inside the loop because it's different for each email


-- the 'my' keyword is needed because you're calling a handler from within a tell block

set htmlContent to my tid(htmlTemplate, "*LOGO*")

set htmlContent to my tid(htmlContent, thisBrand as list) -- thisBrand is an item in the full list

end considering


-- create a new message. visible must be false for the 'html content' line to work correctly

set newMessage to makenewoutgoing messagewith properties {subject:subjectLine, visible:false}

tell newMessage


-- create a variable recipient address based on brand name


logthisBrand


-- Here is the issue!!!!!!!!!!!

if thisBrand is equal to "Kids" then

display dialog "Option A"

else

display dialog "Option B"

end if

set html content to htmlContent


-- send the email


send

end tell

end repeat

end tell

Posted on Apr 7, 2014 2:04 AM

Reply
Question marked as Best reply

Posted on Apr 7, 2014 4:12 AM

Hello


This is typical pitfall in AppleScript repeat loop of this kind, where thisBrand is indeed a reference to item k of brandsToUse and not the item k of brandsToUse itself. And this reference is dereferenced automatically when required in most cases but the equality test is one of the exceptions. You need to dereference it explicitly like this:


repeat with thisBrand in brandsToUse
    set thisBrand to thisBrand's contents -- # dereference thisBrand
    --
    if thisBrand = "Kids" then
        --
    else
        --
    end if
end repeat


Regards,

H

3 replies
Question marked as Best reply

Apr 7, 2014 4:12 AM in response to MattJayC

Hello


This is typical pitfall in AppleScript repeat loop of this kind, where thisBrand is indeed a reference to item k of brandsToUse and not the item k of brandsToUse itself. And this reference is dereferenced automatically when required in most cases but the equality test is one of the exceptions. You need to dereference it explicitly like this:


repeat with thisBrand in brandsToUse
    set thisBrand to thisBrand's contents -- # dereference thisBrand
    --
    if thisBrand = "Kids" then
        --
    else
        --
    end if
end repeat


Regards,

H

Apr 23, 2014 3:50 AM in response to MattJayC

What should happen is that you can select up to all 3 brands


Adult

Kids

Baby


then each brand receives 1 email that corresponds to their brand. So Brand Adult gets an email with a hyper link to adult


Whereas currently brand adult will get the above and then another email with a link to the other brand and so on.


How can I stop this happening?



Hope this makes sense,

Condition Rule ignored?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.