 |
 |
applescript problem (cont.)
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2001
Location: NY, NY, USA
Status:
Offline
|
|
My problem is below. Basically in the first case, I display an item from a list. In case 2, I take the SAME list in string form, convert it to a list type, and then try to display the same item. I am getting an error in the second case and it is driving me insane. It seems the string is not successfully being converted to a list:
set my_list to {{a:"hello", b:"world"}, {a:"hello", b:"world"}}
display dialog a of item 1 of my_list
(* this will display "hello" *)
set my_list to "{{a  "hello\", b  "world\"}, {a  "hello\", b  "world\"}}"
set my_list to my_list as list
display dialog a of item 1 of my_list
(* this SHOULD display "hello" , but displays an error instead! *)
<small>[ 07-09-2002, 07:43 PM: Message edited by: sahara ]</small>
|
|
- Sahara
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
You can't coerce a string containing the AppleScript source code representing a list into the list it represents. Try running these two lines from your script and look at the result window:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">set my_list to "{{a  "hello\", b  "world\"}, {a  "hello\", b  "world\"}}"
set my_list to my_list as list</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">You get a list containing the string you set in the first line as its only item. If you want to parse an arbitrary text input format into lists and/or records, you'll have to do said parsing yourself.
Here's a quick example for one way to do such things:
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">set foo to "ab|cd|ef"
set delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "|"
set bar to every text item of foo
set AppleScript's text item delimiters to delims
get bar</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status:
Offline
|
|
For entertainment purposes only:
Well, I know one way to make Applescript parse a string as a list, but it's pretty gnarly:
copy-and-paste the below to try it
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">set my_list to "{{a  "hello\", b  "world\"}, {a  "hello\", b  "world\"}}"
set command_start to "osascript -e 'set my_list to "
set command_end to "' -e 'return a of item 1 of my_list'"
set result to do shell script (command_start & my_list & command_end)
display dialog result</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">i.e., use the string in an osascript command.
what specifically are you trying to do? maybe we can help if we know exactly what you want to get done.
<small>[ 07-09-2002, 05:43 PM: Message edited by: Mithras ]</small>
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by Mithras:
<strong>For entertainment purposes only:
Well, I know one way to make Applescript parse a string as a list, but it's pretty gnarly:
copy-and-paste the below to try it
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">set my_list to "{{a  "hello\", b  "world\"}, {a  "hello\", b  "world\"}}"
set command_start to "osascript -e 'set my_list to "
set command_end to "' -e 'return a of item 1 of my_list'"
set result to do shell script (command_start & my_list & command_end)
display dialog result</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">i.e., use the string in an osascript command.
what specifically are you trying to do? maybe we can help if we know exactly what you want to get done.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Or even...
set my_list to "{{a  "hello\", b  "world\"}, {a  "hello\", b  "world\"}}"
set my_list to run script my_list
display dialog a of item 1 of my_list
<img border="0" title="" alt="[Wink]" src="wink.gif" />
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2001
Location: NY, NY, USA
Status:
Offline
|
|
Syn's approach works wonderfully.
Since I have peoples' attention, perhaps one of you knows how to solve my one other problem. I am making an app with AppleScript Studio and want to set a variable when I begin resizing a window, and change it again when I finish resizing. I can use the "will resize" handler for the first part, but I don't see any way to handle something like "was resized". Right now, I have the idle handler manually check for such a situation, but that causes a delay before the variable is set when I've finished resizing. There must be a better way. Anyone have any idea? Thanks!
|
|
- Sahara
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Status:
Offline
|
|
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by sahara:
<strong>Syn's approach works wonderfully.
Since I have peoples' attention, perhaps one of you knows how to solve my one other problem. I am making an app with AppleScript Studio and want to set a variable when I begin resizing a window, and change it again when I finish resizing. I can use the "will resize" handler for the first part, but I don't see any way to handle something like "was resized". Right now, I have the idle handler manually check for such a situation, but that causes a delay before the variable is set when I've finished resizing. There must be a better way. Anyone have any idea? Thanks!</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">You can use the "resized" handler. Also, if you need this info to write a list to a preference file.. Rick's method is faster.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2001
Location: NY, NY, USA
Status:
Offline
|
|
I'm actually using both your method and Rickster's in two different places now. Thanks.
As for the resized handler, it is problematic for me. If I start to resize a window and then finish but *don't* let go of the mouse, "resized" occurs. Then if I continue resizing "will resize" and "resize" both happen again. I am looking for something that is truly "resized". That is to say, I've actually let go of the mouse and can't possibly resize again without clicking the resize widget again. As far as I am concerned, if I am still able to drag the mouse around and watch my window resize, I haven't really finished resizing...
|
|
- Sahara
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|