Re: Setting password of a keychain key
Re: Setting password of a keychain key
- Subject: Re: Setting password of a keychain key
- From: kai <email@hidden>
- Date: Sun, 2 Apr 2006 21:41:35 +0100
On 31 Mar 2006, at 12:48, Stephen Jonke wrote:
The {text:thePassword} syntax does seem to do the trick. Thanks
greatly for the help! I didn't know of this type of statement. I
presume this is a kind of "cast"?
Sorry, Steve - meant to come back on this sooner, but somehow kept
getting diverted.
I mentioned earlier that coercing Unicode text to string actually
produces styled text (although it has a class of string). As you
discovered, the residual style data can choke an application that
doesn't know how to handle it. Since styled or international text can
be coerced to record, this serves to demonstrate that we're not
simply dealing with a string of ASCII characters:
-----------
"some text" as Unicode text as string as record
--> {«class ktxt»:"some text", «class ksty»:«data
styl0001000000000010000E00030000000C000000000000»}
-----------
So what's needed is a way to extract the plain text part. While
there's no built-in AppleScript coercion to plain text, Smile or
TextCommands could do the trick. (I even rolled my own vanilla
conversion handler at some stage, albeit not particularly concise or
fast.)
Beyond that, we're pretty much into hack territory. Given the current
ability to coerce to record, we could do stuff like:
-----------
"some text" as Unicode text
«class ktxt» of (result as string as record)
-----------
"some text" as Unicode text
text of (result as text as record) as text
-----------
"some text" as Unicode text
first item of text of (result as text as record)
-----------
All of these methods will error if fed plain text - so, if that's a
possibility, they'd need to be used in conjunction with a try statement.
The {text:some_text} technique, conjured up by the inimitable Arthur
Knapp, exploits the way AppleScript stores data internally - using a
record to extract the text property. Not only is it faster than the
above examples, but it also avoids an error if the incoming string is
plain text.
(I'm sure you don't need me to tell you that an undocumented
'feature' also implies an unwritten health warning - although one
would hope that the need for such tricks could be rendered obsolete
once all applications become Unicode-aware.)
For anyone not already familiar with the 'set record to some object'
syntax, here are a couple of other examples:
-----------
set {name:n, version:v} to application "Finder"
display dialog n & " version: " & v
--> [dialog] "Finder version: 10.4.4" (* or whatever it might be *)
-----------
set {day:d, month:m, year:y} to current date
display dialog "The date is: " & d & space & m & ", " & y & "."
--> [dialog] "The date is: 2 April, 2006." (* or whatever it might be *)
-----------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden