2

선택한 창의 크기를 조정하는 앱을 만들고 있습니다. 모든 창이 선택되면 성공적으로 작동합니다. 그러나 창을 선택하지 않으면 충돌이 발생합니다.Mac OSX : NO 창이 선택되어 있는지 확인하는 방법은 무엇입니까?

현재 다음 코드에서 전면 가장 창을 가져옵니다.

그러나 컨트롤이 바탕 화면에 있는지 또는 모든 창이 비활성화되어 있는지 감지하는 방법.

답변

3

AXUIElementCopyAttributeValue()은 AXError를 반환하므로 잡을 수 있고 check what happened입니다. 특정 경우

AXError error = AXUIElementCopyAttributeValue(frontMostApp, kAXFocusedWindowAttribute, (CFTypeRef *)&frontMostWindow); 
if (error != kAXErrorSuccess) { 
    //solve problems here 
} 

오류의 값이 반환있다 : 당신은이 작업을 수행하는 애플 스크립트를 사용할 수 kAXErrorNoValue = -25212

+0

좋아, 내가 그것을 확인합니다 –

+0

이것은 작동하는 것 같습니다. @eligat 감사합니다. 앞으로 어떤 버그가 발생하지 않기를 바랍니다. –

1

. Xcode에서 새 프로젝트를 만들 때 OS X> 기타로 가서 "Cocoa-AppleScript"를 선택하여 Obj-C와 AppleScript가 모두있는 응용 프로그램을 만들 수 있습니다. 당신은 창

set the bounds of the front window to {x, y, x + width, y + height} 
여기

, xy의 크기를 변경하려면이 코드를 사용할 수 있습니다

tell current app to ... 

의 거리입니다 : 당신은 무언가를 포커스가있는 응용 프로그램을 만들기 위해이 코드를 사용할 수 있습니다 좌상 구석.

프로젝트에 추가하고 현재 앞에있는 창의 크기를 수정할 수 있습니다. 즉, 포커스가있는 앱의 앞면 창이 크기가 조정됩니다. 요세미티에서

set theWindows to the windows of the current application 
if the length of theWindows is 0 then 
    display alert "There are no windows to resize" 
else 
    display dialog "Enter x" default answer "" 
    set x to text returned of result as number 
    display dialog "Enter y" default answer "" 
    set y to text returned of result as number 
    display dialog "Enter width" default answer "" 
    set width to text returned of result as number 
    set width to (x + width) 
    display dialog "Enter height" default answer "" 
    set height to text returned of result as number 
    set height to (y + height) 
    tell current application to set the bounds of the front window to {x, y, width, height} 
end if 

당신이 "스크립트 편집기"응용 프로그램과의 핵심 아무것도하지만 애플 스크립트가없는 애플 리케이션을 만들 수 있습니다 :이 작업과 완벽하게 상호 작용하는 예입니다. Mavericks 및 이전 시스템에서이 응용 프로그램은 "AppleScript 편집기"라고합니다. 앱의 다른 부분에 Objective-C가 필요한 경우 앞에서 설명한 방법을 사용하여 Cocoa-AppleScript 프로그램을 만들 수 있습니다.