But not too much. You create an affine transform for the rotation, and apply that to the graphics context. So the full code then becomes:
use scripting additions
use framework "Foundation"
use framework "AppKit"
set thePath to "/Users/shane/Desktop/Testing4.bmp"
its fileFromClipToPath:thePath
on fileFromClipToPath:thePath
set pb to current application's NSPasteboard's generalPasteboard() -- get pasteboard
set theType to pb's availableTypeFromArray:{current application's NSPasteboardTypeTIFF}
if the theType is missing value then error "No suitable image data found on the clipboard"
-- log theType as text
set theData to pb's dataForType:theType
set oldRep to current application's NSBitmapImageRep's imageRepWithData:theData
-- get size of bitmap
set {width:theWidth, height:theHeight} to oldRep's |size|()
-- calculate new height
set newHeight to theHeight - 50 -- whatever you want to chop off the top
-- make new bitmapImageRep; notice height and width are swapped
set newRep to (current application's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:newHeight pixelsHigh:theWidth bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(current application's NSDeviceRGBColorSpace) bitmapFormat:(current application's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32)
-- create a rotation transform, rotating about the centre of the destination bitmapImageRep
set theTransform to current application's NSAffineTransform's transform()
theTransform's translateXBy:newHeight / 2 yBy:theWidth / 2 -- so it rotates about centre
theTransform's rotateByDegrees:90
theTransform's translateXBy:-theWidth / 2 yBy:-newHeight / 2 -- move it back
-- store the existing graphics context
current application's NSGraphicsContext's saveGraphicsState()
-- set graphics context to new context based on the new bitmapImageRep
(current application's NSGraphicsContext's setCurrentContext:(current application's NSGraphicsContext's graphicsContextWithBitmapImageRep:newRep))
-- set the active color to white
current application's NSColor's whiteColor()'s |set|()
-- fill the bitmapImageRep with white
current application's NSRectFill({origin:{x:0, y:0}, |size|:{width:newHeight, height:theWidth}})
-- apply the transform to the graphics context
theTransform's concat()
-- draw from the original bitmapImageRep to the new one
oldRep's drawInRect:{origin:{x:0, y:0}, |size|:{width:theWidth, height:newHeight}} fromRect:{origin:{x:0, y:0}, |size|:{width:theWidth, height:newHeight}} operation:(current application's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value)
-- restore graphics state
current application's NSGraphicsContext's restoreGraphicsState()
-- save bitmapImageRep as image
set theData to (newRep's representationUsingType:(current application's NSBMPFileType) |properties|:{NSImageProgressive:false})
set theResult to (theData's writeToFile:thePath atomically:true)
-- current application's NSWorkspace's sharedWorkspace()'s openFile:thePath
return (theResult = 1)
end fileFromClipToPath: