--Cocoa crop
set srcImage to NSImage's alloc()'s initWithContentsOfFile_(picPath)
srcView's setImage_(srcImage)
set w to _width's stringValue() as string as number
set h to _height's stringValue() as string as number
set t to _top's stringValue() as string as number
set l to _left's stringValue() as string as number
set destImage to NSImage's alloc()'s initWithSize_({|width|:w, height:h})
set destRect to {|size|:{w, h}, origin:{0, 0}}
set srcRect to {|size|:{w, h}, origin:{l, t}}
destImage's lockFocus()
srcImage's drawInRect_fromRect_operation_fraction_(destRect, srcRect, current application's NSCompositeSourceOver, 1.0)
destImage's unlockFocus()
destView's setImage_(destImage)
--save as png
set theData to destImage's TIFFRepresentation()
set myNsBitmapImageRepObj to NSBitmapImageRep's imageRepWithData_(theData)
set myNewImageData to (myNsBitmapImageRepObj's representationUsingType_properties_(current application's NSPNGFileType, missing value))
if not (myNewImageData's writeToFile_atomically_(picPath, true)) as boolean then
set messageText to "There was an error writing to file"
display dialog messageText buttons {"Ok"}
end if
property myEvent : class "NSEvent" of current application
set mouseloc to myEvent's mouseLocation as list
set {mox, moy} to {x of item 1 of mouseloc, y of item 1 of mouseloc}
(*
A little script to gather any application windows that are partially offscreen in some way and shift them back to the desktop.
This is particularly useful if you use a MacBook with an external display.
*)
tell application "Finder"
-- get desktop dimensions (dw = desktop width; dh = desktop height)
set db to bounds of window of desktop
set {dw, dh} to {item 3 of db, item 4 of db}
end tell
tell application "System Events"
repeat with proc in application processes
tell proc
repeat with win in windows
-- get window dimensions (w = width; h = height)
set {w, h} to size of win
-- get window postion (l = left of window; t = top of window)
set {l, t} to position of win
-- nh = new window height; nw = new window width
set {nh, nw} to {h, w}
-- window width is bigger than desktop size,
-- so set new window width to match the desktop
if (w > dw) then set nw to dw
-- window height is bigger than the desktop size (minus menu bar),
-- so set new window height to be desktop height - 22 pixels
if (h > dh - 22) then set nh to dh - 22
-- r = right coordinate of window; b = bottom coordinate of window
set {r, b} to {l + nw, t + nh}
-- nl = new left coordinate; nt = new top coordinate
set {nl, nt} to {l, t}
-- left coordinate is off screen, so set new left coordinate
-- to be 0 (at the left edge of the desktop)
if (l < 0) then set nl to 0
-- top coordinate is above bottom of menu bar (22 pixels tall),
-- so set new top coordinate to be 22
if (t < 22) then set nt to 22
-- right coordinate extends beyond desktop width,
-- so set new left coordinate to be desktop width - window width
if (r > dw) then set nl to dw - nw
-- bottom coordinate extends beyond desktop height,
-- so set new top coordinate to be desktop height - window height
if (b > dh) then set nt to dh - nh
-- if we have calculated a new top or left coordinate, reposition window
if (l > nl or t > nt) then set position of win to {nl, nt}
-- if we have calculated a new height or width, resize window
if (h > nh or w > nw) then set size of win to {nw, nh}
end repeat
end tell
end repeat
end tell
tell application "TextEdit"
activate
close every document saving no
make new document at the beginning of documents
set the name of window 1 to "Font Samples"
set zoomed of the front window to true
set the text of the front document to "The quick brown fox jumped over the lazy dog."
tell the text of the front document
set the font to "Lucinda Grande"
set the size to 24
end tell
end tell
set ret to my email_check("yourmail@domain.xy")
on email_check(mailadress)
-- 29. Mai 2009, 1.55 Uhr, erarbeitet von H =:o) L G I und macmissionar@gmail.com
try
return (run script (do shell script "perl -nle 'if (/^[^\\,.][A-Z0-9._%+-]+[^\\,.]@[^\\.,](?:[A-Z0-9._%+-]{2,}\\.)[A-Z]{2,4}$/i) {print \"true\"} else {print \"false\"}' <<< " & (quoted form of mailadress)))
on error fehler
return fehler
end try
end email_check
(* These examples uses the curl command, see man pages for further details. *)
--GET Example
property PathToServer : "http://www.qusa.de"
set cmd to "curl -s " & quoted form of (PathToServer & "?com=show")
set ReturnValue to do shell script cmd
--POST Example
property PathToServer2 : "http://www.qusa.de"
set cmd2 to "curl -s '" & quoted form of (PathToServer2 & "?id=59") & "' -d 'xy=51&name2=value2&press=ok'"
set ReturnValue2 to do shell script cmd2
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.