• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to access raw data (as seen in chevron syntax)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to access raw data (as seen in chevron syntax)


  • Subject: Re: How to access raw data (as seen in chevron syntax)
  • From: Matthew Strange <email@hidden>
  • Date: Fri, 2 Jul 2010 17:51:32 -0400

At Fri, 02 Jul 2010 21:36:00 +1000, Shane Stanley wrote:

(I just went to do some testing and discovered that when I try to open a
PICT in Preview.app I get a message that the PICT file format is not
supported in 64-bit mode. So that talk of its being deprecated is true.)

All the more pressure for me to get these PICTs out to files so they can be converted to something else!


Actually, I solved my immediate problem with GraphicConverter -- that has a nice command for making a picture from clipboard data, which can then be saved in whatever format is preferred. My original hope was to use Image Events to do the conversion and avoid requiring the end users to purchase extra software. The rest of this is pure academic pursuit.

Anyway, this seems to work OK in 10.6:

set x to the clipboard as picture -- get PICT data
set fileRef to (open for access file ((path to desktop as text) &
"Test.pict") with write permission)
set eof fileRef to 0
repeat 512 times
    write "a" to fileRef
end repeat
write x to fileRef starting at 513
close access fileRef

It doesn't matter what's written to the first 512 bytes, it seems.


The reason I suggested ascii character 0 (more on that in a moment) is that, in my experiments, the OS X Finder grabs the dimensions out of the header for display (if you have the "show item info" option turned on). I initially wrote "PICTPICT..." into the header, and Finder reported the PICT as having dimensions of 17,134 x 17,134 (give or take a pixel). Writing ASCII 0 in there keeps the OS from showing incorrect info.

(This is why it would be nice to be able to read the bytes in the data -- you could then learn the dimensions of the image and write the correct info into the header. But I digress.)

Also, two folks kindly contacted me off-list to privately point out some foolishness on my part.

1: (ASCII character 0) is deprecated. I should have written (character id 0) so it would work in 10.4 and later. But I should point out that, in OS X 10.4.11 at least, writing "character id 0" into the file results in some unknown text appearing in there. (dle2....obj ...D....) That's probably a Tiger bug. And that makes the Finder info report the image as 17,408x1024 which is the calculated value of the '...D....' bit noted above. (That's bytes 18-25, for those who care.)

2: In my previous reply I suggested writing this into the first 512 bytes:
    write "PICT" to myFile starting at 0
    repeat 498 times
      write (ASCII character 0) to myFile
    end repeat


Hmmm... 4 bytes + 498 bytes = 502... leaving me a bit shy of the required 512 bytes. Folding those two corrections together, it should read:

    write "PICT" to myFile starting at 0
    repeat 508 times
      write (character id 0) to myFile
    end repeat

Hope this helps,
Matt Strange
--
Light travels faster than sound. This must be why some people appear bright until you hear them speak.


_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: How to access raw data (as seen in chevron syntax)
      • From: Shane Stanley <email@hidden>
    • Re: How to access raw data (as seen in chevron syntax) A sketch for a solution to get the picture format data out of the clipboard.
      • From: Tommy Bollman <email@hidden>
  • Prev by Date: Re: How to access raw data (as seen in chevron syntax)
  • Next by Date: Re: How to access raw data (as seen in chevron syntax) A sketch for a solution to get the picture format data out of the clipboard.
  • Previous by thread: Re: How to access raw data (as seen in chevron syntax)
  • Next by thread: Re: How to access raw data (as seen in chevron syntax) A sketch for a solution to get the picture format data out of the clipboard.
  • Index(es):
    • Date
    • Thread