Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

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

creating if statements with 3 options

Hey


I have a Choose from List with 2 items, that if selected will pass the variable through for the Code variable.

But if the variable for Code is not set from the previous selection, i want the option to type a variable for Code.

but it does not ask for input even if there is no previous selection for the Code variable.

Can someone please point out my stupidity 🙂 ?



if answer1 is equal to "PACKAGING" then

set Code to "TA01"

else

if answer2 is equal to "IPOP" then

set Code to "TA02"


else


set Code to text returned of (display dialog ¬

"Enter Code:" with title ¬

"Create Client Folder " with icon 1 ¬


default answer ¬

"" buttons {"Cancel", "Next…"} ¬


default button 2)

end if

end if

Applescript-OTHER, Mac OS X (10.7.4)

Posted on Jul 3, 2012 5:14 PM

Reply
13 replies

Jul 3, 2012 5:47 PM in response to Jacques Rioux

This might give a bit of a clearer picturer




set the_folder to "Volume Name"

set name_list to {}
tell application "Finder"
          set letter_folders to every folder of folder the_folder
  
          repeat with this_folder in letter_folders
                    set name_list to name_list & name of every folder of this_folder
          end repeat
          set theChosenOne to (choose from list name_list) as text
          if result is equal to "Name1" then
                    set job to (choose from list {"PACKAGING", "IPOP"}) as text
                    set theChosenOne to theChosenOne & ":" & job
          end if
end tell



if job is equal to "PACKAGING" then
          set Code to "TA01"
else if job is equal to "IPOP" then
          set Code to "TA02"
else
          set Code to text returned of (display dialog ¬
                    "Enter Client Code:" with title ¬
                    "Create Client Folder " with icon 1 ¬
  default answer ¬
                    "" buttons {"Cancel", "Next…"} ¬
  default button 2)
end if


set Num to text returned of (display dialog ¬
          "Enter Number" with title ¬
          "Create Client Folder " with icon 1 ¬
 default answer ¬
          "" buttons {"Cancel", "Next…"} ¬
 default button 2)

Jul 3, 2012 5:57 PM in response to b3nnb

Looks like you want to set code manually if job is not equal to either TA01 or TA02. Is that correct?

So somehting like


set Code to ""


if job is equal to "PACKAGING" then
set Code to "TA01"
else if job is equal to "IPOP" then
set Code to "TA02"

end


if Code is equal to "" then

set Code to text returned of (display dialog ¬
"Enter Client Code:" with title ¬
"Create Client Folder " with icon 1 ¬
default answer ¬
"" buttons {"Cancel", "Next…"} ¬
default button 2)

end


there are other ways to accomplish this but this might just be the simplest way given your example.


regards


Message was edited by: Frank Caggiano actually looking at the other response I don't see why that isn't working for you.

Jul 3, 2012 6:02 PM in response to b3nnb

b3nnb wrote:


This might give a bit of a clearer picturer


Ok

----------------------

set the_folder to "Volume Name"

set name_list to {}

tell application "Finder"

repeat with this_folder in (get folder of folder the_folder)

set name_list to name_list & name of every folder of this_folder

end repeat

set theChosenOne to (choose from list name_list) as text

set job to ""

if result is equal to "Name1" then

set job to (choose from list {"PACKAGING", "IPOP"}) as text

set theChosenOne to theChosenOne & ":" & job

end if

end tell


if job is "" then

set Code to text returned of (display dialog ¬

"Enter Client Code:" with title ¬

"Create Client Folder " with icon 1 ¬

default answer "" buttons {"Cancel", "Next…"} ¬

default button 2)

else if job is equal to "PACKAGING" then

set Code to "TA01"

else if job is equal to "IPOP" then

set Code to "TA02"

end if


set Num to text returned of (display dialog ¬

"Enter Number" with title ¬

"Create Client Folder " with icon 1 ¬

default answer "" buttons {"Cancel", "Next…"} ¬

default button 2)

Jul 3, 2012 6:17 PM in response to Jacques Rioux

Jacques Rioux wrote:


Ok

----------------------

set the_folder to "Volume Name"

set name_list to {}

tell application "Finder"

repeat with this_folder in (get folder of folder the_folder)

set name_list to name_list & name of every folder of this_folder

end repeat

set theChosenOne to (choose from list name_list) as text

set job to ""

if result is equal to "Name1" then

set job to (choose from list {"PACKAGING", "IPOP"}) as text

set theChosenOne to theChosenOne & ":" & job

end if

end tell


if job is "" then

set Code to text returned of (display dialog ¬

"Enter Client Code:" with title ¬

"Create Client Folder " with icon 1 ¬

default answer "" buttons {"Cancel", "Next…"} ¬

default button 2)

else if job is equal to "PACKAGING" then

set Code to "TA01"

else if job is equal to "IPOP" then

set Code to "TA02"

end if


set Num to text returned of (display dialog ¬

"Enter Number" with title ¬

"Create Client Folder " with icon 1 ¬

default answer "" buttons {"Cancel", "Next…"} ¬

default button 2)

That seems like a closer step. even if it gets the variable TA01 or TA02, it still asks to enter a code manually after words

Jul 3, 2012 6:20 PM in response to b3nnb

Are you sure it is Code that is not defined and not Job?


Just noticed you can possibly not have job set when you go to use it.



This works


set Code to ""

set job to ""





if job is equal to "PACKAGING" then

set Code to "TA01"

else if job is equal to "IPOP" then

set Code to "TA02"

end if


if Code is equal to "" then

set Code to text returned of (display dialog ¬

"Enter Client Code:" with title ¬

"Create Client Folder " with icon 1 ¬


default answer ¬

"" buttons {"Cancel", "Next…"} ¬


default button 2)

end if

Jul 3, 2012 6:37 PM in response to b3nnb

So then just do as I showed


set job to ""

set Code to ""


at the top of your code then the chnages either I or Jaquaes showed whoucl work.


Here's the problem section of your code:

        end repeat
set theChosenOne to (choose from list name_list) as text
if result is equal to "Name1" then
set job to (choose from list {"PACKAGING", "IPOP"}) as text
set theChosenOne to theChosenOne & ":" & job
end if

So if result is not equal to Name1 then job never gets set and you get the error later on. If you set job to "" at the top of your code you'll be OK.


Message was edited by: Frank Caggiano - OK just saw you got it. Glad it helped. regards

creating if statements with 3 options

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