toggling Hot Corners with AppleScript

I’ve been trying to figure out how to make an AppleScript app that will turn my Hot Corners off and another that will turn them back on again (If I can do it with just one let me know!). I can’t figure out how to do it, and the scripts look at online don’t work, so I can’t figure out how to do it by looking at them. If someone could show me how, point me to a place I could learn, or just simply post a working script, that would be awesome. (it’s not an option on the post so I’ll just say it here, I have OS X 10.9)

Model: MacBook Air 2013
AppleScript: 2.6
Browser: Safari 537.71
Operating System: Other

Hi Masondeanm,

You could probably do it by using ui element scripting with the Mission Control preference pane. It looks like a pain to me. :slight_smile:

gl,
kel

Hello. Pain. No pain no gain…

This is just hypothesis, and nothing I’m going to try before Christmas. :slight_smile:

You can try to toggle the corners and figure out in what properties list file it gets stored in, or where the hot corners are stored anyway.

Then, you update that file with the values you want the hot corners to have.

The next step is a hack that hopefully still works:

You open the preference pane, and thereby forces the preferences of mission control to be read in. (This used to work.)
Then, you close the preference pane by some simple ui scripting like keystroke “w” using command down.

At this stage, your new settings should take effect.

Good luck! :slight_smile:

Hi Masondeanm,

Here’s a script I got here a while back from Richard Kulesus and made it into a toggle script. However, it doesn’t work as of os x 10.9, which is your current operating system. The specific error returned is

I gotta see what the new way to access this is…

The call to class epas is to get the current status of the hot corners so that the script can be used as a toggle. I can’t seem to find the new way to access that. Anyone know? McUsr, looking your way :slight_smile:

Here’s the script:

-- By Richard Kulesus, 2009.  Released without license!
-- Use this for whatever!
-- I seriously despise code authors who copyright tiny bits of obvious code
-- like it's some great treasure.  This is small and simple, and if it saves
-- the next guy some time and trouble coding applescript I'll feel good!
--
-- Quickly change all the hot-corners to do what you want.
-- Particularly useful for presentations and full-screen games.
-- Customize the activity of each hot-corner with "all windows/application windows/dashboard/disable screen saver/none/show desktop/show spaces/sleep display/start screen saver/notification center"
-- The MODIFIERS are the keys which can be used to supplement hot-corner activation.
-- Here I've set them all to {}, which is none.  Options are "command/control/none/option/shift"
-- Dashboard in a fullscreen application.
--
-- Version 1.0
--  - Initial release
--

(*
Compartmentalized by Tim Wilson
*)

on run
	set hotCornersActive to hotCornersEnabled()
	if hotCornersActive then
		disableHotCorners()
	else
		enableHotCorners()
	end if
end run

on hotCornersEnabled()
	tell application "System Events"
		activate
		if UI elements enabled then
			tell «class epas»
				if («class epsa» of the «class eptl») is «constant epacnone» then
					return false
				else
					return true
				end if
			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\""
				quit
			end tell*)
		end if
	end tell
end hotCornersEnabled

on enableHotCorners()
	tell application "System Events"
		activate
		if UI elements enabled then
			tell «class epas»
				set properties of the «class eptl» to {«class epsa»:«constant epacallw», «class epso»:{}}
				set properties of the «class eptr» to {«class epsa»:desktop folder, «class epso»:{}}
				set properties of the «class epbl» to {«class epsa»:«constant epacappw», «class epso»:{}}
				set properties of the «class epbr» to {«class epsa»:«constant epacstar», «class epso»:{}}
			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\""
				quit
			end tell*)
		end if
	end tell
end enableHotCorners

on disableHotCorners()
	tell application "System Events"
		activate
		if UI elements enabled then
			tell «class epas»
				set properties of the «class eptl» to {«class epsa»:«constant epacnone», «class epso»:{}}
				set properties of the «class eptr» to {«class epsa»:«constant epacnone», «class epso»:{}}
				set properties of the «class epbl» to {«class epsa»:«constant epacnone», «class epso»:{}}
				set properties of the «class epbr» to {«class epsa»:«constant epacnone», «class epso»:{}}
			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\""
				quit
			end tell*)
		end if
	end tell
end disableHotCorners