• 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: Screencapture
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Screencapture


  • Subject: Re: Screencapture
  • From: Shane Stanley <email@hidden>
  • Date: Sat, 08 Mar 2014 09:34:54 +1100

On 8 Mar 2014, at 6:52 am, Stan Cleveland <email@hidden> wrote:

perhaps Hiroto's code could provide some clues for an ASObjC version? 

Alas, no, in that those APIs aren't available to ASObjC.

It may be doing exactly what Shane suggested--capturing the entire screen, then cropping it.

No, it's getting just the desired portion. Not that cropping is very difficult:

use framework "Foundation"
use framework "AppKit"

on cropTo:{x1, y1, x2, y2} fromPath:inputPath toPath:outputPath
set newWidth to x2 - x1
set newHeight to y2 - y1
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:inputPath
set theSize to (theImage's |size|()) as record
set oldHeight to height of theSize
-- transpose y value for Cocoa coordintates
set y1 to oldHeight - newHeight - y1
set newRect to {{x:x1, y:y1}, {width:newWidth, height:newHeight}}
theImage's lockFocus()
set theRep to current application's NSBitmapImageRep's alloc()'s initWithFocusedViewRect:newRect
theImage's unlockFocus()
set theData to theRep's representationUsingType:(current application's NSPNGFileType) |properties|:{NSImageGamma:1.0}
theData's writeToFile:outputPath atomically:true
end cropTo:fromPath:toPath:

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Screencapture
      • From: Andreas Kiel <email@hidden>
References: 
 >Screencapture (From: Andreas Kiel <email@hidden>)
 >Re: Screencapture (From: Stan Cleveland <email@hidden>)

  • Prev by Date: Re: Screencapture
  • Next by Date: Re: Screencapture
  • Previous by thread: Re: Screencapture
  • Next by thread: Re: Screencapture
  • Index(es):
    • Date
    • Thread