首页 > 解决方案 > 苹果脚本 | 属性“AXFrontmost”,为什么不能设置为false?

问题描述

我无法将“AXFrontmost”属性值更改为 false

如您所见,这段代码生成了一个循环

tell application "System Events"
    
    set front_process to name of first process whose frontmost is true
    
    tell process front_process
        try
            repeat while (value of attribute "AXFrontmost") is true
                set value of attribute "AXFrontmost" to false
            end repeat
            
        on error
            get properties of attribute "AXFrontmost"
            
        end try
    end tell
    
end tell

并且相对于属性属性“AXFrontmost”,settable 的值为 true

我发现将最前面的FORCE设置为 false 的方法是切换可见状态:

repeat while (value of attribute "AXFrontmost") is true
    set visible to false
    delay 0.01
    set visible to true
end repeat

另一种方法是使用 CMD + TAB 键码:

repeat while (value of attribute "AXFrontmost") is true
    key code 48 using command down
end repeat

那么,为什么会发生这种行为?假设可设置属性为真。

有没有其他方法可以强制属性“AXFrontmost”的值为 false?除了我上面已经提到的那些?

标签: applescriptautomator

解决方案


好吧,只有一个进程可以是最前面的。

为此,我只想«告诉应用程序查找器激活»这应该为每个进程将最前面的标志设置为 false。要将 Finder 的标志设置为 false,«告诉我激活»应该可以工作。


推荐阅读