Restore Keyboard shortcuts and screenshots shortcuts

bryancowie
New Contributor II

Does anyone have a way to restore defaults for keyboard and screenshot shortcuts? I perform a method that can be placed in self-service, but I am open to all possible solutions. 

We have testing software that changes the defaults to both of these areas, and upon exiting the testing software, the defaults are not restored. 

macOS version 13.6.1 and higher. 

5 REPLIES 5

iamYaje
New Contributor III

Are you attempting to automate the process of defaulting the shortcuts? I was just doing some keyboard work today for our classrooms and found that I needed to defaults some shortcuts on a few computers that had been altered, in order for certain Apple Script commands to go smoothly. I simply used the built-in GUI to restore defaults in System Settings > Keyboard > Keyboard Shortcuts. That may not be helpful, as I only had to do it for a few computers this time.

bryancowie
New Contributor II

Hello,

 

Thank you for the response. Yes, ideally, I would place a button in self-service for the end user to press that would execute the same action as the "restore defaults" button under Settings > Keyboard > Keyboard Shortcuts. Currently, we are instructing users to use the Settings > Keyboard > Keyboard Shortcuts method, but a single click within self-service would be more straightforward for the end users. Thanks again for the response. 

iamYaje
New Contributor III

I'm not familar with any command line tools that could be scripted for that action, if they even exist. That said it might be possible to capture the PLIST content within ~/Library/Preferences/ or /Library/Preferences/ of the default keyboard shortcuts and deliver that content with a script at the push of a button in Self Service. 

It looks like these settings exist in: com.apple.symbolichotkeys.plist

It looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>AppleSymbolicHotKeys</key>
	<dict>
		<key>15</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>16</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>164</key>
		<dict>
			<key>enabled</key>
			<false/>
			<key>value</key>
			<dict>
				<key>parameters</key>
				<array>
					<integer>65535</integer>
					<integer>65535</integer>
					<integer>0</integer>
				</array>
				<key>type</key>
				<string>standard</string>
			</dict>
		</dict>
		<key>17</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>18</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>19</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>20</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>21</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>22</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>23</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>24</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>25</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>26</key>
		<dict>
			<key>enabled</key>
			<false/>
		</dict>
		<key>60</key>
		<dict>
			<key>enabled</key>
			<false/>
			<key>value</key>
			<dict>
				<key>parameters</key>
				<array>
					<integer>32</integer>
					<integer>49</integer>
					<integer>262144</integer>
				</array>
				<key>type</key>
				<string>standard</string>
			</dict>
		</dict>
		<key>61</key>
		<dict>
			<key>enabled</key>
			<false/>
			<key>value</key>
			<dict>
				<key>parameters</key>
				<array>
					<integer>32</integer>
					<integer>49</integer>
					<integer>786432</integer>
				</array>
				<key>type</key>
				<string>standard</string>
			</dict>
		</dict>
		<key>79</key>
		<dict>
			<key>enabled</key>
			<true/>
		</dict>
		<key>80</key>
		<dict>
			<key>enabled</key>
			<true/>
		</dict>
		<key>81</key>
		<dict>
			<key>enabled</key>
			<true/>
		</dict>
		<key>82</key>
		<dict>
			<key>enabled</key>
			<true/>
		</dict>
	</dict>
</dict>
</plist>

You would need to know the keycodes for the various shortcuts, but if you capture this from a Mac that has the defaults set and then deliver it with a script it might work.

Another thought is that you could try using a script to delete the Property List file entirely. It's just supposition on my part, but that might result in MacOS recreating the file anew with the defaults set, which is your goal. Could be worth trying on a test machine.

iamYaje
New Contributor III

Sorry, let me repharse: the settings MIGHT exist in com.apple.symbolichotkeys.plist

iamYaje
New Contributor III

I ran composer after making changes to the keyboard shortcuts, and it does appear that com.apple.symbolichotkeys.plist contains that data. Just to test it out, I ran a simple script to delete that file from the user's Library. It only brought back the keyboard shortcut defaults after I initiated a user-logout or computer restart in my testing... You could do something like this:

#!/bin/bash

# Path to the keyboard shortcut preference list in the current user's library
PREF_LIST="~/Library/Preferences/com.apple.symbolichotkeys.plist"

# Remove the preference file
rm "$PREF_LIST"

# Use AppleScript to create a dialog box for optional restarting
osascript <<EOD
tell application "System Events"
    display dialog "In order for keyboard defaults to take affect, a computer restart is necessary." buttons {"Restart Now", "Restart Manually Later"} default button 2
    if the button returned of the result is "Restart Now" then
        do shell script "shutdown -r now" with administrator privileges
    end if
end tell
EOD

The idea being to get a dialog box offering to restart now or have the user restart later. If a script like this was set up in Self Service, with a restart initiated, it could work.

It's volitile in the sense that it's not recomended to delete Property List files directly, but generally speaking that particular Propety List is pretty specific to these shortcuts.

More advanced, experienced users here can chime in and say whether this is a good or bad approach. I just want to give you some ideas.