AppleScript in automator error ("The action "Run AppleScript" encountered an error ")

beretis picture beretis · Jul 17, 2016 · Viewed 8.8k times · Source

I wanted to find a way how to disable/enable hot corners via keyboard shortcut. I found this apple script

property theSavedValues : {"Mission Control", "Desktop", "Dashboard", "Launchpad"} -- for example

tell application "System Preferences"
    set current pane to pane id "com.apple.preference.expose"
    tell application "System Events"
        tell window "Mission Control" of process "System Preferences"
            click button "Hot Corners…"
            tell sheet 1
                tell group 1
                    set theCurrentValues to value of pop up buttons
                    if theCurrentValues is {"-", "-", "-", "-"} then
                        repeat with i from 1 to 4
                            set thisValue to item i of theSavedValues
                            tell pop up button i
                                click
                                click menu item thisValue of menu 1
                            end tell
                        end repeat
                    else
                        copy theCurrentValues to theSavedValues
                        repeat with i from 1 to 4
                            tell pop up button i
                                click
                                click last menu item of menu 1
                            end tell
                        end repeat
                    end if
                end tell
                click button "OK"
            end tell
        end tell
    end tell
    quit
end tell

So I created an service in Automator with this apple script, attached it to keyboard shortcut, whenever I run this script in automator, it works but when i hit the shortcut, im getting "The action "Run AppleScript" encountered an error ". Any ideas what can be done to fix this? Thank you

Answer

beretis picture beretis · Jul 17, 2016

Oh my god I feel so dumb, the only thing needed was to grant accessibility permission to app from which I'm using this service :).

You can do this by going to (Mac OS)Settings -> Security&Privacy -> Accessibility -> and finding the app from which you are running the service. (In my case it's Finder.)