Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > applescript problem (cont.)

applescript problem (cont.)
Thread Tools
Forum Regular
Join Date: Apr 2001
Location: NY, NY, USA
Status: Offline
Reply With Quote
Jul 9, 2002, 11:55 AM
 
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
Reply With Quote
Jul 9, 2002, 03:09 PM
 
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 &quot;{{a&quot;hello\&quot;, b&quot;world\&quot;}, {a&quot;hello\&quot;, b&quot;world\&quot;}}&quot;
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 &quot;ab|cd|ef&quot;
set delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to &quot;|&quot;
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">
Rick Roe
icons.cx | weblog
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jul 9, 2002, 04:41 PM
 
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 &quot;{{a&quot;hello\&quot;, b&quot;world\&quot;}, {a&quot;hello\&quot;, b&quot;world\&quot;}}&quot;
set command_start to &quot;osascript -e 'set my_list to &quot;
set command_end to &quot;' -e 'return a of item 1 of my_list'&quot;

set result to do shell script (command_start &amp; my_list &amp; 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
Reply With Quote
Jul 9, 2002, 06:17 PM
 
</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 &quot;{{a&quot;hello\&quot;, b&quot;world\&quot;}, {a&quot;hello\&quot;, b&quot;world\&quot;}}&quot;
set command_start to &quot;osascript -e 'set my_list to &quot;
set command_end to &quot;' -e 'return a of item 1 of my_list'&quot;

set result to do shell script (command_start &amp; my_list &amp; 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" />
     
sahara  (op)
Forum Regular
Join Date: Apr 2001
Location: NY, NY, USA
Status: Offline
Reply With Quote
Jul 9, 2002, 06:42 PM
 
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
Reply With Quote
Jul 9, 2002, 07:46 PM
 
</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.
     
sahara  (op)
Forum Regular
Join Date: Apr 2001
Location: NY, NY, USA
Status: Offline
Reply With Quote
Jul 9, 2002, 10:55 PM
 
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
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2