Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for records? #2

Open
angry-dan opened this issue Jun 10, 2013 · 1 comment · May be fixed by #3
Open

Support for records? #2

angry-dan opened this issue Jun 10, 2013 · 1 comment · May be fixed by #3

Comments

@angry-dan
Copy link

So I want to run an AppleScript similar to this one:

tell current track
  set export to {name:name, album:album, artist:artist}
end tell

Which works just fine, except what is returned is an array ['name:name', 'album:album', etc], rather than a keyed hash.

I've had a look at applescript-parser.js and I think UndefinedParser currently the best place for this:

  while (!END_OF_TOKEN.test(cur)) {
    if (cur === ':') {
      var key = this.value.substring(this.index, end-1);
      this.index = end;
      var value = parseFromFirstRemaining.call(this);
      return {key: key, value: value};
    }
    cur = this.value[end++];
  }

Then, in ArrayParser:

    if (next.key) {
      rtn[next.key] = next.value;
    } else{
      rtn.push(next);
    }

This does need more work though, because it won't determine if rtn should be an array or hash and that creates issues later.

@ghost
Copy link

ghost commented Sep 17, 2013

Here's an ad hoc solution for applescript records, FWIW:

    # convert applescript record to a js object
    # trim off last char, quote the keys before :"
    # now it looks like json
    # then fix date and array formats

    j = JSON.parse out.slice(0,-1).replace(/(\w+)\:\"/g, '"$1":"')
    j.creation_date = (new Date j.creation_date).toJSON()
    j.modification_date = (new Date j.modification_date).toJSON()
    a = j.position.split(',')
    j.position = new Array parseInt(a[0]), parseInt(a[1])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant