My script works but how can I get rid of the quotations from my result?

Discussion in 'Mac Programming' started by aaricwon, Nov 23, 2015.

  1. aaricwon macrumors newbie

    Joined:
    Nov 17, 2015
    #1
    I have the application (script below) that opens a prompt where you enter the serial number and it automatically takes you to the page on everymac.com that shows you the info on that model.

    I actually figured out (sort of) what I wanted to do BUT it leaves quotes in the box. How do I remove the quotes?

    Code:
    [B]set[/B] strSerialNumber [B]to[/B] ""
    
    # get string from terminal
    
    [B]set[/B] strIOPlatformSerialNumber [B]to[/B] [B]do shell script[/B] "ioreg -l | grep IOPlatformSerialNumber"
    
    # work with returned string to get results from last token
    
    # set custom delimiters 
    
    [B]set[/B] AppleScript'stext item delimiters [B]to[/B] "="
    
    [B]set[/B] lstIOPlatformSerialNumber [B]to[/B] [I]text items[/I] [B]of[/B] strIOPlatformSerialNumber
    
    [B]set[/B] strSerialNumber [B]to[/B] [I]item[/I] 2 [B]of[/B] lstIOPlatformSerialNumber
    
    # reset script engine delimiters
    
    [B]display dialog[/B] "Enter Serial Number" default answerstrSerialNumber
    
    [B]set[/B] serial_num [B]to[/B] text returned [B]of[/B] result
    
    [B]set[/B] url_to_open [B]to[/B] "http://www.everymac.com/ultimate-mac-lookup/?search_keywords=" & serial_num
    
    [B]tell[/B] [I]application[/I] "Safari"
    
        [B]activate[/B]
    
        [B]open location[/B]url_to_open
    
    [B]end[/B] [B]tell[/B]
    [code]
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    To get a contiguous range of characters within a text object, use the text element. For example, the value of the following statement is the text object "y thi":

    Code:
    get text 3 thru 7 of "Try this at home"
    --result: "y thi"
    --or
    get text 2 thru -2 of "'123456789'"
    
    How did you get all those B and I tags in your code? Please remove them.
    Note: There's always more than one solution to a problem.
     
  3. aaricwon thread starter macrumors newbie

    Joined:
    Nov 17, 2015
    #3
    The line :
    display dialog[/B] "Enter Serial Number" default answerstrSerialNumber

    Is what gives me the serial number.

    I don't know if the code you gave me will strip the quotes. It gets its answer from:
    AppleScript'stext item delimiters to "="

    And you are right. It looks annoying but I just copied and pasted from Applescript Editor

     
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    Code:
    set strSerialNumber to item 2 of lstIOPlatformSerialNumber
    
    set strSerialNumber to text 3 thru -2 of strSerialNumber
    
     
  5. aaricwon thread starter macrumors newbie

    Joined:
    Nov 17, 2015
    #5
    THANK YOU!
     
  6. aaricwon thread starter macrumors newbie

    Joined:
    Nov 17, 2015
    #6
    My Next question is.... how hard would it be to do the same thing in X CODE?
     
  7. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #7
    Imho, doing something like this in xcode would be overkill.
     

Share This Page