Leopard Breaks Most of My Scripts

I am trying to migrate to Leopard, however, I am running into trouble with my Applescripts. Leopard has broken most of them and I don’t have a clue why. Generally, no error is produced, they just don’t work. All were developed under Tiger and work fine there. Is there some document that describes how to make Applescripts compatible between Tiger and Leopard? Why do they break under Leopard in the first place? TIA.


Some possible reasons:
¢ GUI scripts must always be checked after a major update, because UI elements can change
¢ some known bugs (e.g creating a outgoing message in Mail.app within a rule)
¢ the disappearance of the disk “network” in System Events
¢ The major change, that the text class in Leopard is Unicode based unlike MacRoman based in Tiger
¢ sorry, but also bad coding. Tiger might be more fault-tolerant in some cases

I have also ran into Tiger/Leopard issues but mainly with parsing unicode text files. As StefanK noted there is a major difference in type between the two OS’s and it can be very frustrating.

The only thing good about Leopard I have seen is error logging actually works! I suggest adding try statements with display dialog and error_message. Leopard will give a good ideal of what broke.

Also I have seen some strange compiling bugs with AppleScript Editor. I have reported the bugs to Apple (still awaiting a response).

Ex. The Editor will get very confused when compiling and say that variables that are set are not. And sometimes adding text to a line that is comment the editor will try to compile the line as if it’s code.

From my experience with Leopard if the Editor gets whack you need to log your user out and log back in and it’s seems to fix the issue.

Thanks for the replies. The main script I need at the moment processes email (I’m not producing a new message just extracting data). I have tried inserting some “display dialog” commands but they don’t seem to produce any output when embedded in an “on perform mail action” block. Is there a special way to do that in this case?

In rule scripts all user interaction is disabled,
therefore I always test rule scripts this way

-- using terms from application "Mail"
-- 	on perform mail action with messages theMessages for rule theRule
tell application "Mail" to set theMessages to selection

-- 	end perform mail action with messages
-- end using terms from

Thanks. I’ll give it a try.

Thanks for the help getting some debug to work. I now know what the problem is but not how to fix it. Apparently the Applescript delimiters behave differently under Leopard. Here is the failing code segment:

set data_part to words 1 thru -1 of data_array

What I need, and what works under Tiger, is to change the string ‘data_array’, which was a line read from the email, into the array ‘data_parts’ where each substring, separated by one or more spaces, becomes an item. What do I need to do to this statement so that it works the same under both Tiger and Leopard? I tried various ways of changing “AppleScript’s deliminters” but is appears Leopard ignores those statements. Thanks.

As the command says, text item delimiters affects only text items, not characters, words or paragraphs.
This behavior in Tiger and Leopard is equal

As I said it doesn’t seem to matter. Changing ‘words’ to ‘text items’ fails as does changing ‘text item delimiters’ and ‘word delimiters’. Leopard definitely behaves differently then Tiger for me. Under Tiger using ‘words’ is fine, under Leopard using ‘words’ results in every non-alphanumeric character being used as a delimiter. For example, given the following ‘data_array’:

some.domain.com 543

Under Tiger using ‘words’ and the default delimiters, yields two items in ‘data_part’, {“some.domain.com”,“543”}. This is what I want. Under Leopard the same script yields 4 items, {“some”,“domain”,“com”,“543”}. When I change the ‘word delimiters’ to just a space, the results are exactly the same in both cases. When I switch to ‘items’ with default delimiters, Tiger yields {“some”,“domain”,“com”,“543”} and Leopard yeilds {“s”,“o”,“m”,“e”,“.” … }. When I change the ‘item delimiters’ to just a space, Tiger yields {“some.domain.com”,“543”} and Leopard yields {“s”,“o”,“m”,“e”,“.” … }. Which is why I made the statement that Leopard seems to ignore delimiters settings. In any case the bottom line is that I cannot get Leopard to work at all while Tiger seems to work as expected in all cases. I’d prefer to have a script that works for both but at this point I am so frustrated with Leopard that I’d settle for any thing that will work with it.

Hi, gw1500se.

As Stefan says, text item delimiters only affect ‘text items’. With plain-text strings, ‘words’ depend on the local character set. With Unicode text, which is used exclusively by AppleScript and Script Editor under Leopard, ‘words’ often obey different rules:

-- In Script Editor before Leopard, most English-language systems:

words of "some.domain.com 543"
--> {"some.domain.com", "543"}

words of ("some.domain.com 543" as Unicode text)
--> {"some", "domain", "com", "543"}

As you can see, the second example is identical to what you get in Leopard, where Unicode text (called ‘text’ in Leopard) is the only option.

Most of this is rubbish, I’m afraid. There are no such things as ‘word delimiters’ or ‘item delimiters’ and you shouldn’t use ‘items’ to extract stuff from text.

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set x to text items of "some.domain.com 543"
set AppleScript's text item delimiters to astid

--> {"some.domain.com", "543"}

This should work anywhere, provided there’s only one space in the text.

Hmm. That was one of the many iterations I tried to no avail. When I paste just your script it works so I need to work more with my own to see what might be causing the difference. Thanks.

Right, I’m using words only, if they are (reliably) separated by space characters.
For everything else I use text item delimiters or some shell parse command

Apparently the problem is not what I thought. It seems the problem is consecutive occurrences of white space. This was not a problem with Tiger. So how do I strip multiple white space to replace them it with a single one? Why would Apple make scripts OS dependent?

Don’t blame Apple, blame the scripter, who makes the scripts OS dependent ;):wink:

The decision to change the primary text class in AppleScript to Unicode based is a hugh advance for the language.
For every major update Apple publishes release notes, which contain the changes and the compatibility problems and solutions


Furthermore there are a few terms in AppleScript, which do indeed depend on international settings
like the date and number format.

Thanks. There are 2 strikes against me. 1) I am not an AppleScript expert as I only use it when I don’t have another choice. 2) Because of 1), the release notes are pretty much Greek. Any scripts that are OS dependent are that way because the examples I stole worked. :slight_smile: I have no idea what makes one OS dependent. I guess I’ll need to search for a whitespace remover to steal. One that is not OS dependent. :slight_smile:

I think you want the non-space bits rather than single-spaced text. For a short input text like yours, something like this is good:

set inputText to "some.domain.com               543  "

-- Get the space-delimited text items of the input text.
-- Between adjacent instances of the delimiter, or before an instance at the beginning
-- or after an instance at the end, there are nominally text items of zero-length, which
-- are represented as empty texts: "".
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set textItems to text items of inputText
--> {"some.domain.com", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "543", "", ""}
set AppleScript's text item delimiters to astid

-- Get the items from the list that aren't "".
set x to {}
repeat with i from 1 to (count textItems)
	set thisTextItem to item i of textItems
	if ((count thisTextItem) > 0) then set end of x to thisTextItem
end repeat

--> {"some.domain.com", "543"}

Alternatively (I don’t want to disappoint StefanK :P):

set test to "some.domain.com 543\nanother.example.com 1024"

do shell script "echo " & quoted form of test & " | /usr/bin/grep --only-matching -e '^[^ ]\\+' -e '[0-9]\\+$'"
set example to paragraphs of result
--> {"some.domain.com", "543", "another.example.com", "1024"}
set test to "some.domain.com 543\nanother.example.com 1024"

do shell script "echo " & quoted form of test & " | /usr/bin/awk '{ print $1 } { print $2 }'"
set example to paragraphs of result
--> {"some.domain.com", "543", "another.example.com", "1024"}