• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: String works, variable that's a string does not.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: String works, variable that's a string does not.
  • From: Nigel Garvey <email@hidden>
  • Date: Thu, 29 Apr 2004 11:11:30 +0100

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.


  • Prev by Date: Re: Osascript and ssh
  • Next by Date: Re: Unique Identifier for Disk
  • Previous by thread: Re: String works, variable that's a string does not.
  • Next by thread: Applescript from Excel button
  • Index(es):
    • Date
    • Thread