Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Accessing Hot Corners using AppleScript in Mavericks

Hello,


I'm trying to update a previous utility that could be used to disable/turn off hot corners using an applescript (the script was taken from https://gist.github.com/klynch/827581 and is pasted below). Trying to update it for Mavericks, I saw that the 'top left screen corner' can no longer be used to refer to hot corners. Google has uncovered a 'stack exchange' question that seems to purport that it is not possible anymore (http://apple.stackexchange.com/questions/106775/how-to-fast-set-hot-corners-in-m avericks). Is that true?


If that is indeed true, is there a work-around to my work-around? Specifically, is there a way to easily disable hot corners for when I go into a full screen application or anything like that? I'm thinking something like Caffeine, but for hot corners and not for power saving options. Thoughts?


Thanks in advance!



Disable Hot Corner:

tell application "System Events"

activate

if UI elements enabled then

tell expose preferences

set properties of the top left screen corner to {activity:none, modifiers:{}}

set properties of the top right screen corner to {activity:none, modifiers:{}}

set properties of the bottom left screen corner to {activity:none, modifiers:{}}

set properties of the bottom right screen corner to {activity:none, modifiers:{}}

end tell

else

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.universalaccess"

display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\""

end tell

end if

end tell


tell application "System Preferences" to quit

MacBook Air, OS X Mavericks (10.9)

Posted on Nov 17, 2013 7:32 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 3, 2017 10:43 AM

An old thread but in case someone else wants to get this working on Sierra, I believe the System Events error can be fixed by adding a short delay after loading the Mission Control pane. While commenting out the "activate" line works, that makes the script run invisibly in the background as Pierre noted. Adding "launch" did not fix the error on my machine.


tell application "System Preferences"


activate

set current pane to paneid "com.apple.preference.expose"


delay 0.3

...

act

14 replies
Sort By: 
Question marked as Top-ranking reply

Jan 3, 2017 10:43 AM in response to Pierre L.

An old thread but in case someone else wants to get this working on Sierra, I believe the System Events error can be fixed by adding a short delay after loading the Mission Control pane. While commenting out the "activate" line works, that makes the script run invisibly in the background as Pierre noted. Adding "launch" did not fix the error on my machine.


tell application "System Preferences"


activate

set current pane to paneid "com.apple.preference.expose"


delay 0.3

...

act

Reply

Nov 18, 2013 8:13 AM in response to aspanu

If you just want to disable hot corners, the following script should do the trick:


tell application "System Preferences"

-- activate

set current pane to pane id "com.apple.preference.expose"

tell application "System Events" to tell process "System Preferences"

tell window "Mission Control"

click button "Hot Corners…"

tell sheet 1

repeat with i from 1 to 4

tell pop up button i of group 1

click

click last menu item of menu 1

end tell

end repeat

click button "OK"

end tell

end tell

end tell

quit

end tell

Reply

Nov 18, 2013 9:23 AM in response to aspanu

However, if you wish to be able to toggle between to states of the hot corners (enabled/disabled), the following script would be more appropriate:


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


tell application "System Preferences"

activate

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

Reply

Nov 19, 2013 12:16 PM in response to Pierre L.

Pierre,


Thanks so much for all of your help - especially for the toggle script - it looks like it is exactly what I'm looking for.


Unfortunately, when I try to run it from AppleScript Editor, it gives me an error that:


"System Events got an error: Can’t get window \"Mission Control\" of process \"System Preferences\"." number -1728 from window "Mission Control" of process "System Preferences"


I tried to use a few different keywords instead of process, but, as you can probably tell, I'm a little out of my element on AppleScript. I have also tried to change the order of the syntax to match the first script that you pasted here - i.e. have " System Events to tell process "System Preferences" tell window "Mission Control" ... ", but that didn't seem to work either. In all cases, the Mission Control preferences window pops up, but it doesn't move from there.


Is this a security issue outside of AppleScript and with my system or is this an issue with the script itself?

I have already given AppleScript editor permission to 'change my system' under the accessibility options in "Security and Privacy". Are there any other settings I'll need to change?


Thanks again!


Best,

Adrian

Reply

Nov 19, 2013 12:51 PM in response to aspanu

Hi Adrian,


Well… After reading your post, I created a new standard user on my MacBook Pro in order to test the script again. I copied both versions of the script directly from Safari and pasted each of them into its own AppleScript Editor window. Both versions of the script worked flawlessly (under OS X version 10.9). I wasn't even asked to give any permission to change the system.


So, unfortunately, I can't help you. I hope someone else will find out what's going on with your system.

Reply

Nov 19, 2013 1:02 PM in response to aspanu

Just an idea (maybe silly): did you try commenting out the “activate” line of code in the toggle script? Who knows?


Like this:


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


tell application "System Preferences"

--activate

setcurrent panetopaneid "com.apple.preference.expose"

tellapplication "System Events"

[…]


Something else: it may take several seconds before you notice anything happening the first time the script is run. However, the script normally runs very fast.

Reply

Nov 19, 2013 3:05 PM in response to aspanu

On my system, the script works correctly with or without the “activate” line. In both cases, however, the System Preferences window is invisible, which is contrary to the behaviour found under the previous versions of OS X. In order to make the Mission Control window visible, I discovered that I had to change the beginning of the script as follows:


tell application "System Preferences"

launch

activate

setcurrent panetopaneid "com.apple.preference.expose"

tell application "System Events"

… and so on


Many thanks for your feedback, Adrian. I'm glad I could help you.

Reply

Mar 12, 2014 11:27 AM in response to Pierre L.

This script looks great! Would anyone know how to attach this to a button within X-Code. I have a small app for maintence that I am willing to share. I would like to attach the script to a button but it is having trouble with the "Property theSavedValues " line. Any help is appreciated.

Reply

Accessing Hot Corners using AppleScript in Mavericks

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.