1

I'm working with iTunes via AppleScript. The artwork element of a track contains image data (or raw data, which appears in practice to return the same thing), which can be retrieved and, say, directly written to a file. (It's an e.g. PNG bytestream.)

But I don't know how to do anything with this thing besides write it to a file. I'd like to ask it how many bytes it contains, or even rummage through it (though the latter may well be out of scope for AppleScript). In Script Debugger, it looks like «data tdtaXXXXXX.....» (hex values where I wrote the XXXs), and the iTunes scripting dictionary doesn't link through to any useful type/class for it.

I'm not really sure what the guillemets mean in AppleScript, or what the nature of this object is, or whether this thing can be interrogated natively. Any references on this would be helpful. Thanks!

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204

1 Answers1

3

See https://books.google.com/books?id=rW5k0w_wC3MC&pg=PA57&lpg=PA57&dq=guillemets+applescript+events+data&source=bl&ots=ogzi9W4jxW&sig=7ct-n0wpzdhBhtHDJtTrZDKgEEk&hl=en&sa=X&ei=-qSYVICZAsjooASo0oKwCg&ved=0CB4Q6AEwAA#v=onepage&q=guillemets%20applescript%20events%20data&f=false for explanation of raw codes and data and use of guillemets in AppleScript; See this answer:

Getting artwork from current track in Applescript

for an example of writing image data from iTunes artwork to file.

Community
  • 1
  • 1
CRGreen
  • 3,406
  • 1
  • 14
  • 24
  • Nice link! => Page 49, "Chapter 3 - Data Types": and description on Page 56. –  Dec 23 '14 at 05:45
  • I remembered: on OS 9 there was an osax (Scripting Extension) that could do things with objects. –  Dec 23 '14 at 07:57
  • Yes, that was "Akua Sweets" I believe. One of my first favorite geek-outs in AppleScript back in the day. – CRGreen Dec 23 '14 at 08:04
  • I think this answer would be fully complete if in addition to the (excellent) resources provided, it demonstrated an example of writing the contents of the data type to a file, then reading it back as a string or a list of byte values for manipulation, then changing it back to a data type. This link seems pertinent to the discussion: http://macscripter.net/viewtopic.php?pid=113600#p113600 ... and, oh yeah, Akua Sweets! Thanks for the memory! – Ivan X Dec 23 '14 at 13:06
  • There was also the Programmer's Tool osax by Ed Lai. But I've had a hard time finding anything that really gives any other useful information on data other than an interesting use of xxd (command line, via `do shell script`) to 'coerce' data to/from other types. I'm afraid my 'answer' is quite crappy. – CRGreen Dec 24 '14 at 03:58
  • @CRGreen: Thanks for the answer & info. It sounds like the `data` "class" really isn't manipulatable in any useful way besides forcible conversion to text-hex or whatever. Unfortunate. I'm also surprised that the most lucid documentation on the guillemets comes from an out of print paper book. AppleScript has some expressive power but what a confusing wasteland of a technology. Shame. Thanks! – Ben Zotto Dec 28 '14 at 20:16
  • @BenZotto, it's a common complaint that AS is too 'high level' to be a serious tool. In pre-OSX days, us AppleScript weirdos relied on developers providing extra power through the development of Scripting Additions (osaxen), like Ed Lai and that strange fellow from Switzerland who did Akua. That was, I think, the philosophy behind AS: give them a reasonable learning curve & interapplication communication and let the osaxen and scriptable apps provide more power. I'm afraid not enough developers have taken up the mantle to provide that depth with OSX. At least we have `do shell script` now. – CRGreen Dec 28 '14 at 21:27
  • 1
    @CRGreen: Yes, it seems what community exists around AS has shrunk to be near empty, which as you suggest would otherwise help. That plus broken/bitrotted/undocumented app behaviors, a frankly bewildering language environment (with incomplete/confusing alternatives: scripting bridge, AppleScriptObjC, JXA) make for a real bummer of a situation. For what it's worth, I settled on using the ObjC scripting bridge for this project-- the AS `data` objects can be turned directly into `NSData` objects and manipulated without bouncing to disk. – Ben Zotto Dec 28 '14 at 21:38
  • @BenZotto I am looking for a way to convert NSData (which I got from an AS-Objc invocation) into a raw data string. Can you elaborate? I could make it a SO question if that helps. – Thomas Tempelmann Apr 26 '19 at 10:21
  • @ThomasTempelmann You should start a new question, but fwiw in ObjC if you have an `NSData` (from any source not just AS), you can turn it into various strings but that depends on what you want: hex bytes, encoded text, etc. – Ben Zotto Apr 26 '19 at 15:39
  • @BenZotto See https://stackoverflow.com/a/55870034/43615 - I still struggle with returning an NSData object from my app. Do you know about that? The rest has been solved, see link to Shane Stanley's answer on macscripter.net – Thomas Tempelmann Apr 26 '19 at 16:43