Hi, I am trying to develop an AppleScrit to take a Screenshot with coordinates and set the clipboard with the image. I have 2 scripts very well developed that do something similar
Scripts 1 from a developer called Hiroto from japan takes a screenshot with coordinates but saves it to the desktop no clipboard code.
set {l, t, r, b} to {911, 173, 1738, 794}
set {x, y, w, h} to {l, t, r - l, b - t}
screencapture(x, y, w, h)
on screencapture(x, y, w, h)
(*
number x, y, w, h: rectangle parameters
(x, y) = x, y-coordinates of origin point
(w, h) = width and height of rectangle
* screen shot is saved as ~/Desktop/yyyy-mm-dd hh.mm.ss.png
*)
set args to ""
repeat with a in {x, y, w, h}
set args to args & space & ("" & a)'s quoted form
end repeat
considering numeric strings
if (system info)'s system version < "10.9" then
set ruby to "/usr/bin/ruby"
else
set ruby to "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby"
end if
end considering
do shell script ruby & " <<'EOF' - " & args & "
require 'osx/cocoa'
include OSX
raise AugumentError, \"Usage: #{File.basename($0)} x, y, w, h\" unless ARGV.length == 4
x, y, w, h = ARGV.map {|a| a.to_f}
outfile = File.expand_path(%x[date +'NOMBREFOTO %F %H|%M|%S.png'].chomp, '~/Desktop')
img = CGDisplayCreateImageForRect(CGMainDisplayID(), CGRectMake(x, y, w, h))
brep = NSBitmapImageRep.alloc.initWithCGImage(img)
data = brep.objc_send(
:representationUsingType, NSPNGFileType,
:properties, {})
data.objc_send(
:writeToFile, outfile,
:atomically, false)
EOF"
end screencapture
Script 2 Takes a screenshot and sets the clipboard with it but no coordinates can be set.
tell application "System Events" -- get frontmost process
set frontmostProcess to first process where it is frontmost -- this will be the script process
set visible of frontmostProcess to false -- hide the script process
repeat while (frontmostProcess is frontmost) -- wait until the script is hided
delay 0.2
end repeat
do shell script "screencapture -c -x -m"
end tell
tell current application
activate
end tell
Pleas any idea how can I make the first script to set the image to the clipboard and not to save it as png.
any idea will help!!!
thank you!!!
brian