Format of data?

Here’s a simple one, I am sure.

I think the issue must be the format of the data but I can’t figure out what the problem is. I am trying to send a serial number to netOctopus Agent, a background application running on the machine. The serial number is successfully extracted in the first half of the script. It’s the second part that’s failing.

-- Get the machine serial number from system profiler
set Profile to do shell script "/usr/sbin/system_profiler SPHardwareDataType"
set SN_Start to ((offset of "Serial Number" in Profile) + 15)
set Partial to text SN_Start thru (length of Profile) of Profile
set mySerial to text 1 thru 11 of Partial
-- Result is something like: "ABCDEF12345", 11 characters long.

-- Feed it to netO Agent
tell application "netOctopus Agent"
	set serial number to mySerial
end tell

This fails with the error: “netOctopus Agent got an error: Parameter error.” I don’t assume you are familiar with netOctopus so let me add a few more details:

The following script gets the result:

tell application "netOctopus Agent"
	get serial number -- result: "ABCDEF12345" (numbers and letters, 11 characters, surrounded by quotes)
end tell

The following script is successful:

tell application "netOctopus Agent"
	set serial number to "ABCDEF12345"
end tell

If I try to set the serial number to something other than 11 characters, I get the same parameter error.

It looks to me like I am passing the exact same string back to netO via the variable mySerial but apparently something is different.

Can someone clue me in?

Thanks!

Michael

looks like its a string.
try this notice the as string i added.

-- Get the machine serial number from system profiler
set Profile to do shell script "/usr/sbin/system_profiler SPHardwareDataType"
set SN_Start to ((offset of "Serial Number" in Profile) + 15)
set Partial to text SN_Start thru (length of Profile) of Profile
set mySerial to text 1 thru 11 of Partial as string
-- Result is something like: "ABCDEF12345", 11 characters long.

-- Feed it to netO Agent
tell application "netOctopus Agent"
   set serial number to mySerial 
end tell

I figured ‘as string’ was it, too, but it didn’t work. Same result.

Somehow the format of the numbers is wrong, but I don’t know how or what to coerce it to.

If I look at the event log, I can see that netO gets the following command (and fails):

set serial number to “ABCDEF12345” → “netOctopus Agent got an error: Parameter error.”

But if I copy that very line into a new script, it works.

Hi.

I think the difference may be because when it’s written into the script, the string is compiled as ‘plain text’, whereas when it’s coerced from the Unicode returned by the shell script, it’s something called ‘international text’. netOctopus Agent may only understand plain text. I’ve added a little hack by Arthur Knapp that returns a plain text result. Does it solve the problem?

-- Get the machine serial number from system profiler
set Profile to do shell script "/usr/sbin/system_profiler SPHardwareDataType"
set SN_Start to ((offset of "Serial Number" in Profile) + 15)
set Partial to text SN_Start thru (length of Profile) of Profile
set {text:mySerial} to text 1 thru 11 of Partial as string
-- Result is something like: "ABCDEF12345", 11 characters long.

- Feed it to netO Agent
tell application "netOctopus Agent"
	set serial number to mySerial 
end tell

Thanks, that worked!

I knew it somehow had to be something to do with the text format.

I had not heard of the difference between international and plain text, nor of that nifty little trick for coercing the result to plain text.

-Michael