• 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: 'Make new attachment' dilemma
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'Make new attachment' dilemma


  • Subject: Re: 'Make new attachment' dilemma
  • From: Yvan KOENIG <email@hidden>
  • Date: Tue, 26 May 2015 13:39:44 +0200

Some times ago, Shane Stanley posted here this script converting the image embedded in a PDF file into a jpeg one:

use scripting additions
use framework "Foundation"
use framework "AppKit"

on jpegFromPath:imagePath compressFactor:compFactor -- 0.0 = max compression, 1.0 = none
-- build destination path
set pathNSString to current application's NSString's stringWithString:imagePath
set destPath to pathNSString's stringByDeletingPathExtension()'s stringByAppendingPathExtension:"jpg"
-- load the file as an NSImage
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath
if theImage = missing value then return false
-- get bitmap as data
set theData to theImage's TIFFRepresentation()
-- make imagerep from data
set newRep to current application's NSBitmapImageRep's imageRepWithData:theData
-- turn the imagerep into JPEG data
set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:compFactor, NSImageProgressive:false})
-- write it to disk
set theResult to (theData's writeToFile:destPath atomically:true)
return (theResult = 1)
end jpegFromPath:compressFactor:

its jpegFromPath:(POSIX path of (choose file)) compressFactor:1.0


When we copy a chart from Numbers, the clipboard is filled with these blocks of datas :
{{«class PNGf», 32844}, {«class 8BPS», 251290}, {GIF picture, 13608}, {«class jp2 », 24902}, {JPEG picture, 17032}, {TIFF picture, 435374}, {«class BMP », 432054}, {«class TPIC», 182620}}

I'm wondering if there is a way to grab the TIFF component and convert it into jpeg without using Preview + GUI scripting.

I assume that something like :

use scripting additions
use framework "Foundation"
use framework "AppKit"

on jpegFromPath:thePicture targetPath:thePath compressFactor:compFactor -- 0.0 = max compression, 1.0 = none
set destPath to current application's NSString's stringWithString:thePath
-- load the file as an NSImage
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath # Need to be edited 
if theImage = missing value then return false
-- get bitmap as data
set theData to theImage's TIFFRepresentation()
-- make imagerep from data
set newRep to current application's NSBitmapImageRep's imageRepWithData:theData
-- turn the imagerep into JPEG data
set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:compFactor, NSImageProgressive:false})
-- write it to disk
set theResult to (theData's writeToFile:destPath atomically:true)
return (theResult = 1)
end jpegFromPath:targetPath:compressFactor:

its jpegFromPath:(the clipboard as TIFF picture) targetPath:((path to desktop as text) & "theChart.jpg") compressFactor:1.0

If I understand well the question may be resumed to : 

how must we edit the instruction :

set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath

so that it uses the data extracted from the clipboard.

Of course it may be easier to start from the «JPEG picture» component or from the «class BMP » one.

Yvan KOENIG (VALLAURIS, France) mardi 26 mai 2015 13:35:58



 _______________________________________________
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: 'Make new attachment' dilemma
      • From: Shane Stanley <email@hidden>
References: 
 >Re: 'Make new attachment' dilemma (From: Brian Christmas <email@hidden>)
 >Fwd: 'Make new attachment' dilemma (From: Brian Christmas <email@hidden>)
 >Re: 'Make new attachment' dilemma (From: Christopher Stone <email@hidden>)
 >Re: 'Make new attachment' dilemma (From: Brian Christmas <email@hidden>)

  • Prev by Date: Re: Applescript counting mails keeps counting mail in other folders
  • Next by Date: Using multiple keyboard commands
  • Previous by thread: Re: 'Make new attachment' dilemma
  • Next by thread: Re: 'Make new attachment' dilemma
  • Index(es):
    • Date
    • Thread