Sunday, December 5, 2021
  • Index
  •  » Automator
  •  » Correct Accessibility Permissions? (Automator with Applescript)

#1 2021-04-04 11:47:55 pm

metaning
Member
From:: Australia
Registered: 2020-06-22
Posts: 18

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:

Applescript:


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.

Last edited by metaning (2021-04-05 12:06:31 am)

Offline

 

#2 2021-04-05 01:27:15 am

metaning
Member
From:: Australia
Registered: 2020-06-22
Posts: 18

Re: Correct Accessibility Permissions? (Automator with Applescript)

Just a followup...

Is there a way to modify:

Applescript:


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:

Applescript:


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.

Offline

 

#3 2021-04-05 10:33:42 am

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Correct Accessibility Permissions? (Automator with Applescript)

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

Applescript:


--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

Last edited by db123 (2021-04-05 10:58:05 am)

Offline

 

#4 2021-04-05 11:11:33 am

metaning
Member
From:: Australia
Registered: 2020-06-22
Posts: 18

Re: Correct Accessibility Permissions? (Automator with Applescript)

Hey, thanks for the reply.

So Given I currently have the same...

Applescript:


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,

Last edited by metaning (2021-04-05 11:22:02 am)

Offline

 

#5 2021-04-05 11:46:12 am

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Correct Accessibility Permissions? (Automator with Applescript)

*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?


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

Eg if the uncheck script ran, but the set value was already 0, would it just proceed as if nothing needed doing?


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).

Last edited by db123 (2021-04-05 12:08:51 pm)

Offline

 

#6 2021-04-05 10:28:38 pm

metaning
Member
From:: Australia
Registered: 2020-06-22
Posts: 18

Re: Correct Accessibility Permissions? (Automator with Applescript)

Fantastic, much appreciated smile

Cheers,

Offline

 
  • Index
  •  » Automator
  •  » Correct Accessibility Permissions? (Automator with Applescript)

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)