How to Get Window Reference (Cgwindow, Nswindow or Windowref) from Cgwindowid in Swift

Swift 3 NSWindowStyleMask

window.styleMask.insert(.fullSizeContentView)

Or

window.styleMask = window.styleMask.union(.fullSizeContentView)

Example:

override func windowDidLoad() {
super.windowDidLoad()
guard let window = window else { return }
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
window.styleMask.insert(.fullSizeContentView)
}

Empty Window Controller

How to access the pixel buffer of an NSWindow in OSX?

AFAIK, the official APIs can be found in CGWindow.h as part of CoreGraphics:

/* Create an image containing a composite of the specified set of windows
contained within a rectangular area. The set of windows is specified
using options from `CGWindowListOption', along with an optional
additional window ID.

The windows list options are:

--- kCGWindowListOptionAll, kCGWindowListOptionOnScreenOnly: Use all
on-screen windows in this user session to construct the image. The
parameter `windowID' should be `kCGNullWindowID'.

--- kCGWindowListOptionOnScreenAboveWindow: Use all on-screen windows in
this user session above the window specified by `windowID', ordered from
front to back, to construct the image. To include the window specified by
`windowID', add the flag `kCGWindowListOptionIncludingWindow'.

--- kCGWindowListOptionOnScreenBelowWindow: Use all on-screen windows in
this user session below the window specified by `windowID', ordered from
front to back, to construct the image. To include the window specified by
`windowID', add the flag `kCGWindowListOptionIncludingWindow'.

--- kCGWindowListOptionIncludingWindow: Use only the window specified by
`windowID' to construct the image.

The parameter `screenBounds' specifies the rectangle in screen space
(origin at the upper-left; y-value increasing downward). Setting
`screenBounds' to `CGRectInfinite' will include all the windows on the
entire desktop. Setting `screenBounds' to `CGRectNull' will use the
bounding box of the specified windows as the screen space rectangle.

break

   /* The parameter `imageOptions' allows you to specify whether the window
frame ornamentation, such as a shadow or similar effect, should be
included or excluded in the bounds calculation when `CGRectNull' is
specified for the window bounds.

If no windows meet the specified criteria, or the windows can't be read,
then a transparent black image will be returned.

Any on-screen window with sharing type `kCGWindowSharingNone' will not
be included in the image.

This function returns NULL if the caller is not running within a Quartz
GUI session or the window server is disabled. */

CG_EXTERN CGImageRef CGWindowListCreateImage(CGRect screenBounds,
CGWindowListOption listOption, CGWindowID windowID,
CGWindowImageOption imageOption)
CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA);

/* Create an image containing a composite of the specified set of windows
contained within a rectangular area à la `CGWindowListCreateImage'. The
set of windows is specified by `windowArray', an array of window IDs. */

CG_EXTERN CGImageRef CGWindowListCreateImageFromArray(CGRect screenBounds,
CFArrayRef windowArray, CGWindowImageOption imageOption)
CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA);

Sorry, could not find a link to the documentation on Apple's site. However, they do appear to have sample code in Son of Grab.

How can I minimize/maximize windows in macOS with the Cocoa API from a Python script?

There are probably different ways to do it, out of which one is by enumerating the running applications and next is enumerating the windows inside the application.

I will show the app approach here

from AppKit import NSApplication, NSApp, NSWorkspace
from Quartz import kCGWindowListOptionOnScreenOnly, kCGNullWindowID, CGWindowListCopyWindowInfo

workspace = NSWorkspace.sharedWorkspace()
activeApps = workspace.runningApplications()
for app in activeApps:
if app.isActive():
options = kCGWindowListOptionOnScreenOnly
windowList = CGWindowListCopyWindowInfo(options,
kCGNullWindowID)
for window in windowList:
if window['kCGWindowOwnerName'] == app.localizedName():
print(window.getKeys_)
break
break

This will find the current focused app, you can change the logic based on titles or whatever you want

After the app is found. You can minimize it using

app.hide()

And you can show the app again using

from Cocoa import NSApplicationActivateIgnoringOtherApps, NSApplicationActivateAllWindows
app.unhide()
app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)

# or
app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps | NSApplicationActivateAllWindows)

Lot of threads I had to refer to get to this solution

OS X: Move window from Python

How to list all windows from all workspaces in Python on Mac?

How to get Window reference (CGWindow, NSWindow or WindowRef) from CGWindowID in Swift?

"No such file: 'requirements.txt' error" while installing Quartz module

How to build Apple's Son of grab example?

How to get another application window's title, position and size in Mac OS without Accessibility API?

Get the title of the current active Window/Document in Mac OS X

-[NSRunningApplication activateWithOptions:] not working

How to start an app in the foreground on Mac OS X with Python?

set NSWindow focused

Activate a window using its Window ID

Getting a unique ID for a window of another application

The function HIWindowGetCGWindowID() can only return a CGWindowID for one of your app's windows, since a WindowRef from another program won't be valid in yours.

The function CGWindowListCopyWindowInfo() from CGWindow.h will return an array of dictionaries, one for each window that matches the criteria you set, including ones in other applications. It only lets you filter by windows above a given window, windows below a given window and "onscreen" windows, but the dictionary returned includes a process ID for the owning app which you can use to match up window to app. In each returned dictionary the kCGWindowNumber key will point to the window ID as a CFNumber. There is also a CGWindowListCreate() function that only returns an array of CGWindowIDs. There is basically no documentation for these functions beyond the CGWindow.h header and the Son of Grab sample code. Also, it's 10.5 only.

Find two consecutive rows

Assuming the rows have sequential IDs, something like this may be what you're looking for:

select top 1 * 
from
Bills b1
inner join Bills b2 on b1.id = b2.id - 1
where
b1.IsEstimate = 1 and b2.IsEstimate = 1
order by
b1.BillDate desc


Related Topics



Leave a reply



Submit