Окна Controlling OSX

Использует SQL Server MS, можно сделать следующее:

--List all tables primary keys
select * from information_schema.table_constraints
where constraint_type = 'Primary Key'

можно также отфильтровать на table_name столбце, если Вы хотите определенную таблицу.

12
задан Jorge Israel Peña 14 November 2009 в 03:42
поделиться

6 ответов

One way of doing this is indeed to use the accessibility APIs.

An application I'm developing is doing just this to get the front window, the document path of the front window and many other attributes.

The way I'm doing this is through AppleScript. It can be clumsy at times, but it seems to be fairly reliable. I use AppScript to send AppleScript from within my Cocoa app. It's thread safe and more stable than the alternatives - either Scripting Bridge or NSAppleScript.

The difficult bit will be identifying a window using it's window ID in AppleScript - AppleScript doesn't seem to have a window ID property that matches up to CGWindowID. However, you can get any window you want using AppleScript.

  1. Move frontmost window to 100, 100

    tell application "System Events"
     set theprocess to the first process whose frontmost is true
     set thewindow to the value of attribute "AXFocusedWindow" of theprocess
     set position of thewindow to {100, 100}
    end tell
    
  2. Resize frontmost window to 200, 300

    tell application "System Events"
     set theprocess to the first process whose frontmost is true
     set thewindow to the value of attribute "AXFocusedWindow" of theprocess
     set size of thewindow to {200, 300}
    end tell
    
  3. Change current window of the frontmost application

    tell application "System Events"
     set theprocess to the first process whose frontmost is true
     set thewindow to the value of attribute "AXFocusedWindow" of theprocess
     set size of thewindow to {200, 300}
     windows of theprocess
     -- Code to get ID of window you want to activate
     tell window 2 of theprocess -- assuming it's window 2
     perform action "AXRaise"
     end tell
    end tell
    
  4. Window that's active

    tell application "System Events"
     set theprocess to the first process whose frontmost is true
     set thewindow to the value of attribute "AXFocusedWindow" of theprocess
    end tell
    

There's an application available for AppScript called ASTranslate that will turn this AppleScript into the Objective C code that calls the relevant commands in AppScript.

For more information on how to get the size and bounds of windows (these are read only as far as I'm aware) see the Son of Grab sample application.

11
ответ дан 2 December 2019 в 21:23
поделиться

Accessibility needs to be enabled in System Preferences for this to work. It's applescript, but could be used in objective-c with the scripting bridge.

-- Moves safari window by deltaposition
tell application "System Events"
    tell application "Safari"
        set win to first window
        set b to bounds of win
        set deltaposition to {50, 0}
        set bounds of first window to {(item 1 of b) + (item 1 of deltaposition), (item 2 of b) + (item 2 of deltaposition), (item 3 of b) + (item 1 of deltaposition), (item 4 of b) + (item 2 of deltaposition)}
    end tell
end tell
1
ответ дан 2 December 2019 в 21:23
поделиться

На основании вашего комментария, вы можете сделать это с помощью API специальных возможностей OS X, но я считаю, что «доступ для вспомогательных устройств» должен быть включен в настройках специальных возможностей пользователя.

Там есть стороннее условно-бесплатное приложение, название которого сейчас ускользает от меня, которое позволяет перемещать любое окно (и, я думаю, изменять его размер) с помощью команд клавиатуры.

1
ответ дан 2 December 2019 в 21:23
поделиться

Я думаю, вам следует объяснить, почему вы хотите это сделать. Единственные известные мне утилиты, которые перемещают окна всех других приложений, - это Spaces и Expose, которые поставляются Apple. Если вы хотите захватить весь экран, для этого есть общедоступный API, но перемещение окон других приложений звучит подозрительно.

-1
ответ дан 2 December 2019 в 21:23
поделиться

Я здесь новенький, поэтому это нужно отправлять как ответ, а не комментарий. Я написал приложение .NET ( PlaceMint ), которое делает именно это в Windows и совершенно не вызывает подозрений. PlaceMint поможет вам организовать ваши окна структурированным способом, определенным пользователем. Все, что он делает, это перемещает или изменяет размер окон в соответствии с правилами, определенными пользователем. Кто-то спросил меня, могу ли я сделать порт для OSX, но я так и не продвинулся далеко, потому что не смог найти определение API, подобное тому, которое есть в Windows (маршалинг вызовов dll в user32.dll, например SetWindowPos ()).

-1
ответ дан 2 December 2019 в 21:23
поделиться

Используйте CGWindowListCopyWindowInfo, чтобы получить kCGWindowOwnerPID каждого окна. Затем вы можете использовать «распределенные объекты», если вам нужен доступ к материалам ObjectiveC, или Mach RPC для других вещей. Все это задокументировано на http://developer.apple.com

Есть много веских причин для отправки сообщений другим приложениям — например, при разработке новых пользовательских интерфейсов, которые не являются ни мышью, ни клавиатурой.

2
ответ дан 2 December 2019 в 21:23
поделиться