Applescript:如何仅在未选中复选框时单击复选框?

Applescript:如何仅在未选中复选框时单击复选框?,applescript,Applescript,我想为系统中的所有.app文件启用选项“以低分辨率打开” 这是我的Applescript代码: on run argv tell application "Finder" set myFile to (POSIX file (item 1 of argv)) as alias open information window of myFile activate tell application "System Events"

我想为系统中的所有.app文件启用选项“以低分辨率打开”

这是我的Applescript代码:

on run argv
    tell application "Finder"
        set myFile to (POSIX file (item 1 of argv)) as alias
        open information window of myFile
        activate
        tell application "System Events"
            try
                click checkbox "Open in Low Resolution" of scroll area 1 of (windows where name contains "Info") of process "Finder"
            end try
        end tell
        close information window of myFile
    end tell
end run
我用以下方法运行它:

sudo find / -name *.app -type d -exec osascript myScript.scpt "{}" \;
这项工作非常好:它查找所有“.app”文件,将文件传递给脚本,脚本将打开文件的“信息窗口”,单击“以低分辨率打开”复选框,最后关闭窗口

问题:仅当尚未选中该复选框时,我才需要单击该复选框

我尝试了这个解决方案(和其他类似方案):

什么也没发生。没有错误。

系统事件,应用程序说明ecc。。。允许在安全和隐私设置下运行

这不起作用:

on run argv
    tell application "Finder"
        --set myFile to (POSIX file (item 1 of argv)) as alias
        set myFile to (POSIX file ("/Applications/App Store.app")) as alias
        open information window of myFile
        activate
    end tell
    tell application "System Events" to tell process "Finder"
        try
            set theCheckbox to checkbox "Open in Low Resolution" of scroll area 1 of (windows where name contains "Info") of process "Finder"
            tell theCheckbox
                set checkboxStatus to value of theCheckbox as boolean
                if checkboxStatus is false then click theCheckbox
            end tell
        end try
    end tell
    tell application "Finder"
        delay 1
        close information window of myFile
    end tell
end run
它什么也不做。 以下示例(应用程序信息窗口已打开):

将产生以下错误:

无法使{class chbx»的«class valL»以低分辨率打开 «类别pcap»“Finder”窗口“App Store.App Info”的«类别scra»1 将应用程序“系统事件”}转换为布尔类型

下一步我能做什么


致以最诚挚的问候。

我怀疑问题在于您将所有内容都放在了Finder-tell块中。众所周知,Finder对脚本编写非常挑剔;最好尽量少用

重新安排使用系统事件似乎解决了问题(尽管我的旧MacBookPro没有视网膜屏幕,所以我不得不使用不同的复选框进行测试)。请注意,您不需要激活Finder或信息窗口;你可以在后台完成这一切

on run argv
    set myAppPath to item 1 of argv -- should be a POSIX path

    tell application "Finder"
        open information window of file (POSIX file myAppPath as text)
    end tell
    tell application "System Events"
        set appName to displayed name of disk item myAppPath
        tell process "Finder"
            tell window (appName & " info")
                tell first scroll area
                    if (value of checkbox "Open in Low Resolution" as boolean) is false then
                        click checkbox "Open in Low Resolution"
                    end if
                end tell
                click (first button whose role description is "close button")
            end tell
        end tell
    end tell
end run

find/-name*.app-type d-exec-osascript myScript.scpt“{}”Wowsers。 真勇敢。。。或者你非常非常有耐心。当然,您与之交互的大多数应用程序将位于
/applications
文件夹中。在
/System/Library/CoreServices
中可以找到一些偶尔对访问有用的附加应用程序。继续……继续每一个其他应用程序(假设您自己不将它们移动到随机位置)都将是非GUI的,并且是其他捆绑包的一部分,这些捆绑包对该任务没有什么价值。因此,我将
find
限制为上述两个目录。或者使用
mdfind'kMDItemContentTypeTree==“com.apple.application”c'
;或
mdfind'kMDItemFSName以“.app”结尾
◻︎@CJK-关于“…限制
查找
到上述两个目录”的明智词汇,当然除非“你非常非常有耐心。”
:)
。对于更高性能的Win,我也会考虑使用它的选项来防止它下降到一个应用程序包中(<代码> App)。基本上,
-prune
将避免所有子
.app
,您可以通过按住ctrl键并单击Finder中的应用程序并选择“显示软件包内容”来找到这些子应用程序。非常感谢。它很好用。也要感谢@CJK:现在我在运行脚本时使用了:
mdfind'kMDItemContentTypeTree==“com.apple.application”c';而read-r行;do命令osascript myScript.scpt“$line”;完成
on run argv
    set myAppPath to item 1 of argv -- should be a POSIX path

    tell application "Finder"
        open information window of file (POSIX file myAppPath as text)
    end tell
    tell application "System Events"
        set appName to displayed name of disk item myAppPath
        tell process "Finder"
            tell window (appName & " info")
                tell first scroll area
                    if (value of checkbox "Open in Low Resolution" as boolean) is false then
                        click checkbox "Open in Low Resolution"
                    end if
                end tell
                click (first button whose role description is "close button")
            end tell
        end tell
    end tell
end run