Re: String to list conversion
Re: String to list conversion
- Subject: Re: String to list conversion
- From: Paul Berkowitz <email@hidden>
- Date: Mon, 13 Sep 2004 22:57:10 -0700
Title: Re: String to list conversion
It looks like you need some handling of empty properties. When I run it here I get
ERROR: Can't get paragraph 2 of "".
in the repeat loop.
Stepping through, I discover that, in my case, applescriptPrefs = "", (after the shell script), so none of the rest of the script is testable. I'd guess that this is another of those things where not departing from the defaults mean that I have no user prefs here at all and am using local or system defaults. Here's the contents of my com.apple.applescript.plist in its entirety:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ChooseAppBounds</key>
<string>181 710 712 1262</string>
</dict>
</plist>
I don't know where the defaults are stored, do you? It's certainly the only com.apple.applescript.plist anywhere on my computer.
Also, AppleScript list items, like record label-value pairs and parts of dates are already references. You don't really need 'a reference to' for all the list items. Especially as the references are to undefined variables. You might as well just say
set referenceList to {1, 2, 3, 4, 5, 6, 7, 8}
You can still set item i of referenceList to your various values.
But the best thing would be to populate the referenceList with the default values for applescript formats, whatever and wherever they may be, and only set item i to your user prefs' paragraph if appleScriptPrefs ≠ "", and paragraph i exists (use a try block), and paragraph i ≠ "".
--
Paul Berkowitz
From: Gnarlodious <email@hidden>
Date: Mon, 13 Sep 2004 23:29:35 -0600
To: Applescript <email@hidden>
Subject: Re: String to list conversion
Paul, you’re pretty good at this. Will you look at the latter part of this script and tell me if it looks OK? It just seems a little bulky for what I’m trying to do. Thanks.
-- Recolor Applescript colors for HTML so it doesn’t hurt Martin's eyes
set pListPath to "~/Library/Preferences/com.apple.applescript.plist"
set applescriptPrefs to do shell script "awk '/AppleScriptTextStyles/,/<\\/array>/' " & pListPath & "| sed -n '3,10p' | sed" & ¬
" -e 's| <string>|{\"|' " & ¬
" -e 's|;|\",\"|' " & ¬
" -e 's|;|\",|' " & ¬
" -e 's|;|,{|' " & ¬
" -e 's| |,|g' " & ¬
" -e 's|<\\/string>|}}|' "
set referenceList to {a reference to osaOther, a reference to osaOperator, a reference to osaLanguage, a reference to osaApplication, a reference to osaComments, a reference to osaValues, a reference to osaIdentifier, a reference to osaReference}
repeat with i from 1 to count items of referenceList
set item i of referenceList to run script (paragraph i of applescriptPrefs)
end repeat
item 3 of referenceList
--> {"Verdana", "b", 12, {52428, 13107, 0}}
Entity Paul Berkowitz spoke thus:
> On 9/13/04 9:07 PM, "Gnarlodious" <email@hidden> wrote:
>
>> Say I have an unquoted string direct from a shell script:
>> {"Verdana","b",12,{30583,30583,30583}}
>
> What's an "unquoted string". All strings in AppleScript are surrounded by
> quotes, including all those coming from 'do shell script'. If you mean
> you're "getting it" in Terminal, how do you propose top transfer it to
> AppleScript? Via the clipboard? Or how?" However you do it, it will turn
> into a "quoted" string (either a string, or Unicode, in quotes), complete
> with escaped internal quotes.
>>
>> and I want a list:
>> {"Verdana", "b", 12, {30583, 30583, 30583}}
>>
>> How to?
>
> The usual way. Since that "string" will actually be:
>
>
> "{\"Verdana\", \"b\", 12, {30583, 30583, 30583}}"
>
> the simple way would be to
>
> run script "{\"Verdana\", \"b\", 12, {30583, 30583, 30583}}"
> --> {"Verdana", "b", 12, {30583, 30583, 30583}}
_______________________________________________
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
_______________________________________________
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