Quick newbie AppleScript question

Discussion in 'Mac Programming' started by phreakout13, Oct 7, 2005.

  1. macrumors 6502

    phreakout13

    Joined:
    Jan 4, 2004
    Location:
    South Eastern MA
    #1
    Hello:)
    I'm trying to place a variable within a sentence. Here's an example:
    Code:
    display dialog "What is your name?" default answer "" buttons {"Cancel", "Okay"} default button 2
    copy the result as list to {theText, theButton}
    if theText contains "My name is" then
    	set fourthWord to word 4 of theText
    	display dialog "My name is -this is where the variable should be!- too!"
    end if
    How can I have the variable fourthWord inserted in the middle of that quote? I've looked how to do it everywhere and I'm stumped :confused:
    I'd greatly appreciate someone's help.
    Thanks:)
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    In AppleScript & is the concatenation operator. So your line should be something like:
    Code:
    display dialog "My name is " & fourthWord & " too!"
    
    If you want an AppleScript book I'd recommend AppleScript The Definitive Guide (O'Reilly). This is on page 279!
     
  3. thread starter macrumors 6502

    phreakout13

    Joined:
    Jan 4, 2004
    Location:
    South Eastern MA
    #3
    Thanks a bunch! That will be the next book I buy:)
     

Share This Page