qlassiqa / qWorkflow

AppleScript implementation of the Workflow object class for Alfred 2
81 stars 7 forks source link

Plist corrupted when storing list of records #1

Open surrealroad opened 11 years ago

surrealroad commented 11 years ago

If I do wf's set_value("cacheData", data, cacheFile) where "data" is a list of records, the plist file gets created but with no data.

qlassiqa commented 11 years ago

Hey there,

It's definitely a problem on your side of things, maybe you're doing something wrong. I've tried running the following code samples, and all produced a good plist structure, so maybe you're saving improper data or data that contains something that just can't go inside a plist file.... I can't know until I see what data you're trying to save.

1. saving a simple record wf's set_value("cacheData", {a:2}, "data.plist")

which produced:

...
<key>cacheData</key>
<dict>
    <key>a</key>
    <integer>2</integer>
</dict>
...

2. saving a complex record wf's set_value("cacheData", {b:3, ok:true}, "data.plist")

which produced:

...
<key>cacheData</key>
<dict>
    <key>b</key>
    <integer>3</integer>
    <key>ok</key>
    <true/>
</dict>
...

3. saving a list of records like you mentioned wf's set_value("cacheData", { {a:2}, {b:3, ok:true} }, "data.plist")

which produced:

...
<key>cacheData</key>
<array>
    <dict>
        <key>a</key>
        <integer>2</integer>
    </dict>
    <dict>
        <key>b</key>
        <integer>3</integer>
        <key>ok</key>
        <true/>
    </dict>
</array>
...

Try them out yourself, and eventually use them as guidelines on how to structure your data. Let me know how it went :)

surrealroad commented 11 years ago

yeah sorry, I just realised there's both a set_value and set_values.

EDIT: It also turns out I can't use "name" as a record property :/)

qlassiqa commented 11 years ago

You're obviously doing it the wrong way, because I just tried setting a "name" property with success. The below code runs perfectly fine, and the plist file contains the "name" property ;)

wf's set_value("name", "OK", "")

If you've tried using {name: "value"} as a record, obviously it won't work because name is a reserved word in AppleScript and has other uses, so the only thing you can do if you really want to use name is to enclose it within vertical bars: { |name|: "value" }

However, make sure you read the documentation and look at the provided examples on how to use set_values & set_value, because they don't use that type of records. Here are a few VALID examples on how these methods should be used:

SET_VALUE:

wf's set_value("name", "mike", "")
wf's set_value("my first list", {1, 2, 3, "bob"}, "settings.plist")

SET_VALUES:

set theList to {{theKey:"name", theValue:"mike"}, {theKey:"hobbies", theValue:{"sports", "music"}}}
wf's set_values(theList, "settings.plist")

As you can see, these are the only ways of setting values in a plist file ;)

surrealroad commented 11 years ago

Just to let you know, wf's set_value("cacheData", { {a:2}, {b:3, ok:true} }, "data.plist") appears not to work in OS 10.9 (the other two simpler examples you listed do work)

qlassiqa commented 11 years ago

Well, OS 10.9 hasn't been officially released yet, therefore that OS version might still have bugs

surrealroad commented 11 years ago

sure, just wanted to give you a heads up.