OS detection script... and Path to me problem(10.0)

I wrote a script which detects OS and triggers the right install progame according to the OS version.

It is working well under 9.1, 9.2, 10.2 and 10.3.
But the script is showing a script error under 10.0 and 10.1 .
The error message is “A descriptor type mismatch occured”.

Jason gave me a possible reason, but I can’t test it right now because I do not have version 10. 0 and 10.1 here. I am very in a hurry to solve it out, so I want to know more information.

I appreciate any help.

Below is the script source.

copy my gestaltVersion_info(“sysv”, 4) to {system_version, system_string}
set me_ to path to me
if the system_version is less than “1000” then – this checks for OS X 10.0.0
tell application “Finder”
set appContainer to container of me_ as text
set appInstall to (appContainer & “Classic MacOS:Install”)
open file appInstall
end tell
else
tell application “Finder”
set appContainer to container of me_ as Unicode text
set appInstall to (appContainer & “MacOS X:Install”)
open file appInstall
end tell
end if
on gestaltVersion_info(gestalt_code, string_length)
try
tell application “Finder” to ¬
copy my NumToHex((system attribute gestalt_code), ¬
string_length) to {a, b, c, d}
set the numeric_version to {a, b, c, d} as string
if a is “0” then set a to “”
set the version_string to (a & b & “.” & c & “.” & d) as string
return {numeric_version, version_string}
on error
return {“”, “unknown”}
end try
end gestaltVersion_info
on NumToHex(hexData, stringLength)
set hexString to {}
repeat with i from stringLength to 1 by -1
set hexString to ((hexData mod 16) as string) & hexString
set hexData to hexData div 16
end repeat
return (hexString as string)
end NumToHex

Hi,

The error message “A descriptor type mismatch occured” has fixed by changing “Unicode text” to “text” and the error was happened only under version 10.0.

Now, I have another pronlem with below.

set me_ to path to me
tell application “Finder”
set appContainer to container of me_ as text

After the sentences, appContainer has the current path(eg, Mac HD:MyPath:) which ends with a colon(:slight_smile: under 9.1, 9.2, 10.1, 10.2 and 10.3.
But, I think 10.0 does not have the colon at the end of the path(just Mac HD:MyPath).

I do not have Mac OS X 10.0, so it is very hard for me to check it out.
Can anyone help me to test it?
Thanks in advance.

I do not have Mac OS X 10.0, but II think you can handle this [potential] case another way. Simply test the last character of the string.

set appContainter to container of me_ as text

if (character (length of appContainer) of appContainer) is not “:”
set appContainer to (appContainer & “:”) as string
end if

Cheers.

PS. I know I use some unnecessary grouping, but it makes things a lot easier to read I think.

Thanks Justin.

I will try your suggestion.

By the way, Can you explain the differences of Unicode text, text and string?
When do I use them correctly?

Thans in advance.

I can only explain them in a hand-waving manner. the gory details I don’t really know. I believe the text type will preserve formatting information, where as string is simply the characters of the text. Unicode is an encoding set, I assume you’ve heard of ASCII. Unicode is a newer standard meant to replace ASCII, it is a much larger text set, and can handle languages like Chinese where you have far more than a couple hundred letters, number, and symbols you want to use. Since Apple was doing a complete rewrite of Mac OS, they decided to support and use Unicode extensively. Now if you could only coerce easily from Unicode to strings…

… which can be simplified to: :slight_smile:

if appContainer does not end with ":" then
  set appContainer to appContainer & ":"
end if

But another solution to this potential problem might be simply to dispense with the text paths and stick with the Finder references:

set me_ to path to me
tell application "Finder"
  set appContainer to container of me_
  open file "Install" of folder "MacOS X" of appContainer
end

‘Text’ and ‘string’ are synonyms for class ‘string’ in AppleScript. In a string, each character has a one-byte value, which can thus only be between 0 and 255. If you want to use characters that aren’t in the current character set, you have to switch to a different font where the numbers from 0 to 255 represent a different set of characters.

As Justin said, ‘Unicode text’ has a much larger character set. By using two-byte values for each character, it allows a number range from 0 to 65535, which will (in theory) give instant access to any symbol you may want to use.

Although ‘text’ and ‘string’ are synonyms for the same class, the words themselves aren’t always interchangeable:

  1. When ‘text’ refers to a property rather than a class, there’s usually no ‘string’ equivalent:
text of front document
  1. When extracting strings from a list, ‘text’ can sometimes mean its own plural:
set myList to {1, true, "Hello", {}, "World"}
first text of myList -- = 'first string of myList'
--> "Hello"

-- But:
text of myList -- = 'strings of myList' = 'every string of myList' = 'every text of myList'
--> {"Hello", "World"}
  1. ‘As string’ and ‘as text’ are not interchangeable as parameters for the ‘the clipboard’ command in classic versions of Jon’s Commands or the Standard Commands. However, in OS X versions they are.

Here’s an unofficial method, which might not work so well with non-Latin character sets:

try -- errors on plain text, works for styled or Unicode text
  set myText to «class ktxt» of (myText as record)
end try

-- Or, less efficiently:
try
  set myText to text of (myText as record) as text
end try