0

I want to enable option "Open in Low Resolution" for all ".app" files in the system.

This is my Applescript code:

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

i run it with:

sudo find / -name *.app -type d -exec osascript myScript.scpt "{}" \;

This work very good: it looks for all ".app" files, pass the file to the script, the script will open the "information window" of the file, clicks the "Open in Low Resolution" checkbox and finally it closes the window.

Problem: i need to click on the Checkbox ONLY if is not already selected.

I tried with this solution (and other similar): Tick a checkbox only if it's not selected

Nothing happens. No errors.

System Events, Applescripts ecc... are allowed to run on Security And Privacy Settings

This does not works:

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

It simply does nothing. The following sample (with an app Info Window opened):

tell application "System Events" to tell process "Finder"
    set theCheckbox to checkbox "Open in Low Resolution" of scroll area 1 of (windows where name contains "Info")
    tell theCheckbox
        if not (its value as boolean) then click theCheckbox
    end tell
end tell

Will produce the following error:

Can’t make «class valL» of {«class chbx» "Open in Low Resolution" of «class scra» 1 of window "App Store.app Info" of «class pcap» "Finder" of application "System Events"} into type boolean

What can i do next?

Best regards.

  • 1
    **`find / -name *.app -type d -exec osascript myScript.scpt "{}" \;`** Wowsers. That's brave... Or you're very, very patient. The majority of applications that you interface with will, of course, be in the _`/Applications`_ folder. Some additional applications that are occasionally useful to access can be found in _`/System/Library/CoreServices`_. _Cont'd..._ – CJK Aug 14 '19 at 00:58
  • 1
    _...Cont'd_ Every other app (assuming you yourself don't move them to random places) will be non-GUI, and part of some other bundle that will be of little value for this task. Therefore, I would limit `find` to those two aforementioned directories. Or use **`mdfind 'kMDItemContentTypeTree == "com.apple.application"c'`**; or **`mdfind 'kMDItemFSName ENDS WITH ".app"'`** ◻︎ – CJK Aug 14 '19 at 01:00
  • 1
    @CJK - wise words regarding _"…limit `find` to those two aforementioned directories"_ unless of course _"you're very, very patient."_ `:)`. For a greater performance win, I'd also consider using its [`-prune`](https://ss64.com/osx/find.html) option to prevent it from descending into an application package (`.app`). Essentially `-prune` will avoid all the sub `.app`(s) that you would find by _ctrl_ + _click_'ing on an application in the _Finder_ and choosing _"Show Package contents"_. – RobC Aug 16 '19 at 10:14

1 Answers1

1

I suspect the problem is that you've put everything inside a Finder tell block. The Finder is notoriously finicky about scripting; best to use it as little as possible.

Rearranging things to use System Events seems to fix the problem (though admittedly my old MacBook Pro doesn't have a retina screen, so I had to test this using a different checkbox). Notice that you don't need to activate the Finder or the information window; you can do this all in the background.

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
Ted Wrigley
  • 2,921
  • 2
  • 7
  • 17
  • 1
    Thanks so much. It works fine. Thanks to @CJK too: now i run my script with: `mdfind 'kMDItemContentTypeTree == "com.apple.application"c' | while read -r line; do command osascript myScript.scpt "$line"; done` – Luca Reggiannini Aug 15 '19 at 09:14