Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 调整所有正在运行的应用程序的所有窗口大小_Macos_Resize_Window_Applescript - Fatal编程技术网

Macos 调整所有正在运行的应用程序的所有窗口大小

Macos 调整所有正在运行的应用程序的所有窗口大小,macos,resize,window,applescript,Macos,Resize,Window,Applescript,我正在尝试编写一个applescript脚本,允许我随时调整所有正在运行的应用程序的所有窗口大小(我目前正在使用,但有时发现它有问题,所以我想“重新发明”它) 我一直在关注一些applescripting教程,并提出了以下代码来实现这一点,但它有缺陷: tell application "Finder" set rect to bounds of window of desktop end tell property excludedApplicationNames : {"Finde

我正在尝试编写一个applescript脚本,允许我随时调整所有正在运行的应用程序的所有窗口大小(我目前正在使用,但有时发现它有问题,所以我想“重新发明”它)
我一直在关注一些applescripting教程,并提出了以下代码来实现这一点,但它有缺陷:

tell application "Finder"
    set rect to bounds of window of desktop
end tell

property excludedApplicationNames : {"Finder"}
tell application "System Events"
    say "a"
    repeat with theProcess in processes
        say "b"
        if background only of theProcess is false then
            say "c"
            set theProcessName to name of theProcess as string
            if theProcessName is not in excludedApplicationNames then
                say theProcessName
                tell application theProcess
                    set bounds of windows of process theProcess to rect
                end tell
            end if
        end if
    end repeat
end tell
say "done"
问题是,当此代码遇到我唯一的终端窗口(有几个打开的选项卡)时,它会出错:
System Events出错:无法将应用程序(每个进程的项目2)设置为{0,0,1280,900}。System Events出错:无法将应用程序(每个进程的项目2)设置为{0,0,1280,900}。

告诉应用程序进程
更改为
告诉应用程序进程名
没有帮助(相同的错误),将其更改为
告诉应用程序“系统事件”
(错误:
系统事件出错:无法将每个进程的项目2转换为整数类型。

有趣的是,这与预期一样有效:

tell application "Finder"
    set rect to bounds of window of desktop
end tell

tell application "Terminal"
    repeat with theWindow in windows
        set bounds of theWindow to rect
    end repeat
end tell
所以我很困惑。
我做错了什么?我怎样才能解决这个问题

tell application "Finder"
    set {0, 0, dtw, dth} to bounds of window of desktop
end tell
tell application "System Events"
    repeat with p in (processes where background only is false)
        tell p
            if name is not in {"Finder"} then
                set position of windows to {0, 0}
                set size of windows to {dtw, dth}
            end if
        end tell
    end repeat
end tell
  • 在我的Mac上花了大约3秒钟
  • 最大化终端窗口以填充屏幕(码头占用的4px区域除外)
  • 在我的Mac电脑上花了大约0.3秒
  • 不适用于所有应用程序,如Preview或Reder
  • 使用捆绑标识,因为少数应用程序具有不同的进程和应用程序名称
  • 调整终端窗口的大小,使其上下各有几个像素的空白
我使用此脚本最大化windows:

try
    tell application "Finder" to set dtb to bounds of window of desktop
    tell application (path to frontmost application as text)
        if name is in {"Terminal"} then
            error
        else
            set bounds of window 1 to dtb
        end if
    end tell
on error
    tell application "System Events" to tell (process 1 where it is frontmost)
        try
            click (button 1 of window 1 where subrole is "AXZoomButton")
        end try
    end tell
end try

在许多没有基本AppleScript支持的应用程序中,缩放按钮还可以最大化窗口以填充屏幕。

这最终为我带来了窍门:

property blacklist : {"Finder", "Preview", "Console", "AppleScript Editor", "Spotify", "TaskCoach"}
property buttonApps : {"LyX", "Eclipse"}
property buttonMaps : {{name:"LyX", Button:1, pname:"lyx"}, {name:"Eclipse", Button:2, pname:"eclipse"}}

tell application "Finder" to set theBounds to bounds of window of desktop

tell application "System Events"
    set bids to bundle identifier of processes where background only is false
end tell

repeat with bid in bids
    tell application id bid
        if name is not in blacklist then
            set appName to name as string
            if name is "Terminal" then
                set newBounds to {0, 0, (item 3 of theBounds) - 10, item 4 of theBounds}
                repeat with theWindow in windows
                    if visible of theWindow is true then
                        say appName
                        set bounds of theWindow to newBounds
                    end if
                end repeat
            else if name is not in buttonApps then
                repeat with theWindow in windows
                    if visible of theWindow is true then
                        set bounds of theWindow to theBounds
                    end if
                end repeat
            else if name is in buttonApps then
                -- get the buttonNumber
                repeat with buttonApp in buttonMaps
                    if (name of buttonApp as string) is appName then
                        set theButton to Button of buttonApp
                    end if
                end repeat
                tell application "System Events"
                    repeat with theProcess in (processes where bundle identifier is bid)
                        try
                            tell theProcess to tell window 1 to click button theButton
                        end try
                    end repeat
                end tell
            end if
        end if
    end tell
end repeat
请注意,“Spotify”和“Task Coach”被列入黑名单,因为我无法通过以下方式调整它们的大小:

  • 设置窗口边界
  • 点击绿色按钮
  • 单击菜单栏中的“窗口”>“缩放”
  • 使用⌘我已将其映射到的F10快捷方式

  • 如果有人能想出一个更好的解决方案,我洗耳恭听。这一个要考虑码头的大小。我在显示器的右边有我的,但它应该很容易修改,以适应底部的码头

    tell application "Finder"
        set dtb to bounds of window of desktop
    end tell
    
    tell application "System Events" to tell process "Dock"
        set dockDimentions to size in list 1
        set dockWidth to item 1 of dockDimentions
    end tell
    
    tell application "System Events"
        bundle identifier of processes where background only is false
    end tell
    
    repeat with bid in result
        tell application id bid
            try
                if name is not in {"Finder", "System Preferences", "Notepad", "Terminal", "Activity Monitor"} then
                    set x to item 1 of dtb
                    set y to item 2 of dtb
                    set w to (item 3 of dtb) - dockWidth
                    set h to item 4 of dtb
                    set (bounds of windows) to {x, y, w, h}
                end if
            end try
        end tell
    end repeat
    

    我发现
    告诉应用程序“Finder”将窗口1的边界设置为{0,0,600600}
    也有问题。它适用于某些应用程序,如Finder和iTunes,但是。而且Preview根本不支持AppleScript,因此它的窗口无法通过AppleScript调整大小。我测试了上面三个脚本中的每一个,第一个脚本工作得最好,并最大化了所有应用程序的窗口。与ControlPlane一起使用,连接、断开外部显示器时,不必再担心窗口问题,这是一种享受!!非常感谢。
    tell application "Finder"
        set dtb to bounds of window of desktop
    end tell
    
    tell application "System Events" to tell process "Dock"
        set dockDimentions to size in list 1
        set dockWidth to item 1 of dockDimentions
    end tell
    
    tell application "System Events"
        bundle identifier of processes where background only is false
    end tell
    
    repeat with bid in result
        tell application id bid
            try
                if name is not in {"Finder", "System Preferences", "Notepad", "Terminal", "Activity Monitor"} then
                    set x to item 1 of dtb
                    set y to item 2 of dtb
                    set w to (item 3 of dtb) - dockWidth
                    set h to item 4 of dtb
                    set (bounds of windows) to {x, y, w, h}
                end if
            end try
        end tell
    end repeat