AppleScript question (slightly OT)

B

BB

Hi

I'm writing an appleScript for Entourage 2004 where I want to keep
persistent data between runs.

I've tried to use properties for this, but it seems like the values of my
properties don't "stick".

If I run the script from the script editor it works, but not when I choose
it from the AppleScript menu in Entourage.

Are there any particular tricks I need to do to get this to work?

In it's simplest form my script looks like this

property test: "hello"
display dialog test
set test to "world"

I would expect that the first run of the script should display "hello" and
any consecutive runs should display "world".

It works when I save the script as an application, but then it doesn't show
up in the script menu in Entourage.

Thanks in advance

-Bo
 
B

Barry Wainwright

Hi

I'm writing an appleScript for Entourage 2004 where I want to keep
persistent data between runs.

I've tried to use properties for this, but it seems like the values of my
properties don't "stick".

If I run the script from the script editor it works, but not when I choose
it from the AppleScript menu in Entourage.

Are there any particular tricks I need to do to get this to work?

In it's simplest form my script looks like this

property test: "hello"
display dialog test
set test to "world"

I would expect that the first run of the script should display "hello" and
any consecutive runs should display "world".

It works when I save the script as an application, but then it doesn't show
up in the script menu in Entourage.

Thanks in advance


This bug is due to a limitation in the Data Fork scripts of the latest
incarnation of Applescript - Entourage cannot store script properties.

For a quick and easy fix, download a copy of the free 'Smile' script editor
and save your compiled scripts with that - they are in the 'old' format
which Entourage can handle perfectly.

<http://www.satimage.fr/software/en/smile.html>
 
B

BB

This bug is due to a limitation in the Data Fork scripts of the latest
incarnation of Applescript - Entourage cannot store script properties.

For a quick and easy fix, download a copy of the free 'Smile' script editor
and save your compiled scripts with that - they are in the 'old' format
which Entourage can handle perfectly.

<http://www.satimage.fr/software/en/smile.html>

Thanks, it's working now!

-Bo
 
B

Barry Wainwright

This bug is due to a limitation in the Data Fork scripts of the latest
incarnation of Applescript - Entourage cannot store script properties.

For a quick and easy fix, download a copy of the free 'Smile' script editor
and save your compiled scripts with that - they are in the 'old' format
which Entourage can handle perfectly.

<http://www.satimage.fr/software/en/smile.html>


Additional Info:

Another way, perhaps more 'OS X like', is to use the system defaults
functionality.

To store a default value, use:

Do shell script "defaults write myPrefFile propertyName \"hello\""

This will create (if necessary) a file in the local user preferences folder
called myPrefFile (~/Library/Preferences/myPrefFile.plist). This preference
file will contain a key called 'propertyName' with the value "hello"


Then, when you need the value again, use:

Do shell script "defaults read myPrefFile propertyName"

And the value in that preference key will be returned.

If you are going to use this method, read the prefs value into a local value
or property at run time then use the local value, writing out a new value at
the end if necessary. Accessing the stored preference is considerably slower
(in relative terms) than accessing a local variable.
 
B

BB

Additional Info:

Another way, perhaps more 'OS X like', is to use the system defaults
functionality.

To store a default value, use:

Do shell script "defaults write myPrefFile propertyName \"hello\""

This will create (if necessary) a file in the local user preferences folder
called myPrefFile (~/Library/Preferences/myPrefFile.plist). This preference
file will contain a key called 'propertyName' with the value "hello"


Then, when you need the value again, use:

Do shell script "defaults read myPrefFile propertyName"

And the value in that preference key will be returned.

If you are going to use this method, read the prefs value into a local value
or property at run time then use the local value, writing out a new value at
the end if necessary. Accessing the stored preference is considerably slower
(in relative terms) than accessing a local variable.

I tried this one too and it works fine except for one thing: If the data i
save to the prefs file contains diacritical characters (like the ones we got
in the Swedish alphabet) the data comes back coded. The character "å" (a
ring) comes back as "\\345" when I read it back. It looks ok in the prefs
file when I open it in the property list editor.

Is this a limitation in the shell script "defaults" or can I do anything
about it in my script?

-Bo
 
B

BB

I tried this one too and it works fine except for one thing: If the data i
save to the prefs file contains diacritical characters (like the ones we got
in the Swedish alphabet) the data comes back coded. The character "å" (a
ring) comes back as "\\345" when I read it back. It looks ok in the prefs
file when I open it in the property list editor.

Is this a limitation in the shell script "defaults" or can I do anything
about it in my script?

-Bo

I found the answer: the bash shell does not support these characters
properly.

-Bo
 
B

Barry Wainwright

I found the answer: the bash shell does not support these characters
properly.

Yes, that does seem to be a limitation of this method that I hadn't
encountered. I am looking for a way round it...
 
B

BB

Yes, that does seem to be a limitation of this method that I hadn't
encountered. I am looking for a way round it...

I made a workaround by writing an AppleScript function that will convert the
"\\345" data back into real characters when I read my preference file. I
didn't do it as a generic function but it will cover my Swedish character
problem.

The function looks like this:

to convertSwedish(stringToConvert, theChar, theNumberString)
set ix to offset of theNumberString in stringToConvert
repeat while ix ‚ 0

set textStart to (text items 1 through (ix - 1) of stringToConvert)
as string
set textEnd to (text items (ix + 4) through (count of
stringToConvert) of stringToConvert) as string
set stringToConvert to textStart & theChar & textEnd
set ix to offset of theNumberString in stringToConvert

end repeat

return stringToConvert
end convertSwedish

I call it repeatedly for the characters in question. A typical call looks
like this:

set palmcats to convertSwedish(palmcats, "å", "\\345")

I guess it would be possible to write a generic function that would be able
to convert any character.

-Bo
 
Top