Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aaricwon

macrumors newbie
Original poster
Nov 17, 2015
7
0
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]
 

kryten2

macrumors 65816
Mar 17, 2012
1,115
99
Belgium
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.
 

aaricwon

macrumors newbie
Original poster
Nov 17, 2015
7
0
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

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]
 

kryten2

macrumors 65816
Mar 17, 2012
1,115
99
Belgium
Code:
set strSerialNumber to item 2 of lstIOPlatformSerialNumber

set strSerialNumber to text 3 thru -2 of strSerialNumber
 

aaricwon

macrumors newbie
Original poster
Nov 17, 2015
7
0
My Next question is.... how hard would it be to do the same thing in X CODE?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.