首页 > 解决方案 > 并行运行 AppleScript 处理程序

问题描述

我想并行运行这个 AppleScript 处理程序两次(所以我希望两个调用tillSideBySideWindows("right")异步运行而不是彼此之后),有没有办法做到这一点?

on tillSideBySideWindows(direction)
    tell application "System Events"
        set allVisibleProcessNames to name of processes whose visible is true
        
        repeat with processName in allVisibleProcessNames
            
            set windowsOfCurrentApp to every window of application process processName
            
            repeat with currentWindow in windowsOfCurrentApp
                
                set currentWindowsSize to size of currentWindow
                set currentWindowsWidth to item 1 of currentWindowsSize
                
                set currentWindowsPosition to position of currentWindow
                set currentWindowsLeftPos to item 1 of currentWindowsPosition
                
                if currentWindowsLeftPos = 0 then
                    if direction = "right" then
                        set currentWindowsWidth to currentWindowsWidth + 30
                    else
                        set currentWindowsWidth to currentWindowsWidth - 30
                    end if
                    
                    set currentWindowsHeight to item 2 of currentWindowsSize
                    set winName to name of currentWindow
                    set size of window winName of application process processName to {currentWindowsWidth, currentWindowsHeight}
                end if
                
                if (currentWindowsLeftPos + currentWindowsWidth) = 1680 then
                    set currentWindowsHeight to item 2 of currentWindowsSize
                    
                    if direction = "right" then
                        set currentWindowsLeftPos to currentWindowsLeftPos + 30
                        set currentWindowsWidth to currentWindowsWidth - 30
                    else
                        set currentWindowsLeftPos to currentWindowsLeftPos - 30
                        set currentWindowsWidth to currentWindowsWidth + 30
                    end if
                    
                    set winName to name of currentWindow
                    set position of window winName of application process processName to {currentWindowsLeftPos, 0}
                    set size of window winName of application process processName to {currentWindowsWidth, currentWindowsHeight}
                    get currentWindowsWidth
                end if
            end repeat
        end repeat
    end tell
end tillSideBySideWindows

tillSideBySideWindows("right")

标签: macosasynchronousapplescript

解决方案


推荐阅读