Correct Accessibility Permissions? (Automator with Applescript)

Hi,

Just wondering, I’ve created an Automator action as a Finder Service to process a bunch of PDF files into PNG images, but there’s a problem where the system’s (macOS 10.13) LCD font smoothing adds red & blue fringing to the edges of text.

I realised I can stop that happening if I disable LCD Font Smoothing in the System Preferences, so I hacked together a little bit of Applescript from examples I found online to do the following before it starts processing the files:


tell application "System Preferences"
	activate
	reveal pane id "com.apple.preference.general"
	delay 1
end tell

tell application "System Events"
	click checkbox "Use LCD font smoothing when available" of window "General" of process "System Preferences"
end tell

tell application "System Preferences"
	quit
end tell

I put another copy at the end of the Automator action, so to run it, I select all my pdfs in Finder, right click, Services, my service… Then the system opens System Preferences, toggles LCD Font Smoothing, quits system preferences, runs the automator actions for converting PDF to PNG, then reopens System Preferences, toggles LCD Smoothing back on, & quits System Preferences.

First time I ran it, it didn’t work because of a security dialogue.

Eventually I was able to get it to work be adding Finder to the fist of applications that were ticked to be allowed to control the computer, but I’m wondering if there’s something more specific I should use - Automator is already enabled.

Looking online, macosautomation.com recommends /System/Library/CoreServices/ServicesUIAgent but that doesn’t appear to be on 10.13.

Is there a 10.13 equivalent to allow Applescripts in Automator Actions to control System Preferences etc?

edit I disabled Finder Access and tried to run it again, and this time it asked for Finder access, so I guess that means enabling Finder is the right solution?

Thanks.

Just a followup…

Is there a way to modify:


tell application "System Events"
	click checkbox "Use LCD font smoothing when available" of window "General" of process "System Preferences"
end tell

so that it sets the checkbox to a specific status - checked / unchecked, rather than just telling it to click the checkbox (which just flips whatever state it’s in)?

I’ve tried variations on:


tell application "System Events"
	set checkbox "Use LCD font smoothing when available" of window "General" of process "System Preferences" to 0
end tell

but that doesn’t seem to do it.

Thanks.

You can’t set the value, but you can get the value:


--check
tell application "System Events"
	tell application process "System Preferences"
		tell window "General"
			tell checkbox "Use LCD font smoothing when available"
				if value is 0 then
					click
				end if
			end tell
		end tell
	end tell
end tell

--uncheck
tell application "System Events"
	tell application process "System Preferences"
		tell window "General"
			tell checkbox "Use LCD font smoothing when available"
				if value is 1 then
					click
				end if
			end tell
		end tell
	end tell
end tell

Hey, thanks for the reply.

So Given I currently have the same…


tell application "System Events"
   click checkbox "Use LCD font smoothing when available" of window "General" of process "System Preferences"
end tell

…before and after my Automator actions chain for the image processing (which I worry is unsafe because it presumes the state of that checkbox is checked before I start, I would instead put the uncheck section before, and the check one afterward?

Does Applescript have a failure mode that doesn’t need to be explicitly described? Eg if the uncheck script ran, but the set value was already 0, would it just proceed as if nothing needed doing?

Thanks once again.

edit oh, and I’m assuming your suggestions only replace the part I’ve quoted above, right? I still use the first (opening sysprefs), and third (quitting sysprefs) tells in my starting and finishing scripts?

Cheers,

That’s right. I have only replace the part with the checkbox.

If you use the uncheck-part and the value is already 0, then the script don’t click the checkbox. If you use the check-part, then the checkbox will only clicked if the value is 0 (not 1).

Fantastic, much appreciated :slight_smile:

Cheers,