13 Replies Latest reply: Jul 3, 2012 6:37 PM by Frank Caggiano
b3nnb Level 1 Level 1 (0 points)

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, Mac OS X (10.7.4)
  • Jacques Rioux Level 4 Level 4 (2,685 points)

    Hi,

     

     

    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

  • b3nnb Level 1 Level 1 (0 points)

    Sorry, that still skipped over the section that asks for text input. and just gives me the error

    the variable Code is not set.

  • b3nnb Level 1 Level 1 (0 points)

    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)
    
    
  • Frank Caggiano Level 7 Level 7 (25,720 points)

    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.

  • Jacques Rioux Level 4 Level 4 (2,685 points)

    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)

  • b3nnb Level 1 Level 1 (0 points)

    I still get

    the variable 'Code' is not defined

     

  • Frank Caggiano Level 7 Level 7 (25,720 points)

    Where do you get the error message?  If you entered the script as I wrote Code is defined in all places it could be accessed.

  • b3nnb Level 1 Level 1 (0 points)

    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

  • b3nnb Level 1 Level 1 (0 points)

    the error happens once it gets into the if statement

     

    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 


  • Frank Caggiano Level 7 Level 7 (25,720 points)

    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

  • b3nnb Level 1 Level 1 (0 points)

    Sorry Frank your right, job is not defined.

    im working on so many huge sections of script right now tha i get lost in it.

  • b3nnb Level 1 Level 1 (0 points)

    Frank!!! that was it!!! i just forgot to set the emtpy varialbe.

    Thanks a million

  • Frank Caggiano Level 7 Level 7 (25,720 points)

    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