Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String works, variable that's a string does not.



Michelle Steiner wrote on Wed, 28 Apr 2004 14:43:21 -0700:

>On Apr 28, 2004, at 1:38 PM, Lorin Rivers wrote:
>
>> Howcum?
>
>Because text returned of a dialog is a unicode string, and the file
>type and creators require plain old ASCII strings.
>
>"Set text_returned to text_returned as string" will not do it, even
>though it appears to make the change. here is a work around that
>works:
>
>display dialog "What would you like to set the selected files creator
>to?" default answer "DmWr" buttons {"OK", "Cancel"} default button 1
>copy the result as list to {text_returned, button_pressed}

Although this list setting will usually work, the properties of a record
aren't really guaranteed to be in any particular order. It would be safer
to use:

set {text_returned, button_pressed} to the result's {text returned,
button returned}

or, faster:

set {text returned:text_returned, button returned:button_pressed} to
the result

>set text_returned to text_returned
>set temp to ""
>repeat with loop from 1 to length of text_returned
> set temp to temp & (ASCII character of (ASCII number of character loop
>of text_returned))
>end repeat
>set text_returned to temp

I don't know if it still works in Panther, but the fast hack for ensuring
plain text in Jaguar is:

try
set text_returned to <<class ktxt>> of (text_returned as record)
end try

("<<" and ">>" are the characters produced by pressing option-\ and
shift-option-\ on English-language keyboards.)

>tell application "Finder"
> if button_pressed is "OK" then
> set these_items to the selection
>
> repeat with i from 1 to the count of these_items
> set this_item to (item i of these_items) as alias

> set (creator type of file this_item) to (text_returned)
> end repeat
> end if
>end tell

Ah. Remember the days when this could all be done in one line? :-(

NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.