如何获取和/或覆盖 Mac OSX 中窗口的最小尺寸

发布于 2024-11-02 23:29:16 字数 945 浏览 0 评论 0原文

我想调整我的机器上的任何窗口的大小,这是通过 AppleScript 使用 GUI 脚本。 该脚本看起来类似于以下内容:

tell application "System Events"
  set appProcess to the first process whose name is "Finder"
  set appWindow to the front window of appProcess
  set position of appWindow to {100, 100}
  set size of appWindow to {10, 10}
end tell

即使我将宽度和高度设置为 10px,Finder 也会将大小调整为至少 344px 的宽度和 236px 的高度。我用其他应用程序对此进行了测试,所有应用程序都有一个最小宽度,该宽度根据应用程序而有所不同。例如,TextMate 窗口的大小至少为 213px * 129px。

由于我有时需要将窗口大小调整为较小的宽度和高度,有没有办法覆盖这个最小尺寸,即即使我的值“太小”,也会使用它们?

如果没有,我需要知道最小尺寸,以便我知道窗口将比预期大。我将如何实现这一目标?


具体问题如下:我正在编写一个窗口平铺管理器,因此我需要负责窗口的大小。最小尺寸会产生问题:

  1. 我的图块对于某个应用程序的窗口来说可能太小,因此窗口可能会与其他图块重叠。
  2. 该窗口可能比预期更宽/更高,因此跨越了我的屏幕边界。 (例如,窗口位于屏幕的右下角附近 - 我相应地设置了宽度和高度以适合角落,但由于它有最小尺寸,所以不适合。)

我感谢任何建议。 :)

最美好的祝愿
弗洛里安

I want to resize any window on my machine, which I accomplish with AppleScript, using GUI Scripting.
The script looks similar to the following:

tell application "System Events"
  set appProcess to the first process whose name is "Finder"
  set appWindow to the front window of appProcess
  set position of appWindow to {100, 100}
  set size of appWindow to {10, 10}
end tell

Even though I set the width and height to 10px, the Finder will resize to at least a width of 344px and a height of 236px. I tested this with other applications and all had a minimum width, which differed depending on the application. For example, TextMate windows have a size of at least 213px * 129px.

Since I sometimes need to resize the windows to a smalled width and height, is there a way to override this minimum size, i.e. that my values are used even though they are "too small"?

If not, I need to know the minimum size, so that I know that the window will be bigger than expected. How would I accomplish that?


The concrete problem is the following: I am writing a window tiling manager, therefore I need to be in charge of the size of the windows. The minimum size creates to problems:

  1. My tiles may be too small for windows of a certain application, therefore the windows may overlap in other tiles.
  2. The window may be wider / higher than expected and therefore cross the borders of my screen. (For example, the window is near the lower right corner of my screen - I set the width and height accordingly to fit in the corner, but since it has a minimum size it won't fit.)

I am thankful for any recommendations. :)

Best wishes
Florian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风无影 2024-11-09 23:29:16

正如评论者指出的那样:不可能将窗口大小调整为低于开发期间设置的最小尺寸(例如在 Interface Builder 中)。但是,最小尺寸的存在是有原因的:为了防止自动- 调整大小问题,例如,由于视图尺寸太小,按钮重叠或消失。

感谢巴伐利亚的回答。

PS:Lri 补充说,使用应用程序的 API 可以绕过最小大小,例如使用 Carbon API 来调整 iTunes 的大小或使用自定义构建的 AppleScript-API。谢谢李瑞!

As the commenters pointed out: It is not possible to resize a window below its minimum size which was set during development (e.g. in Interface Builder). However, minimum sizes are there for a reason: To prevent auto-resizing problems, e.g. buttons overlap or disappear due to a too small view size.

Thanks to Bavarious for that answer.

PS: Lri added, that it may be possible to bypass minimum sizes using the API of an application, e.g. using the Carbon API to resize iTunes or using customly build AppleScript-APIs. Thanks Lri!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文