Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created November 8, 2016 21:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pudquick/5aec669ea8a8c920c0960fa05895687f to your computer and use it in GitHub Desktop.
Save pudquick/5aec669ea8a8c920c0960fa05895687f to your computer and use it in GitHub Desktop.
Enable the "Open in Low Resolution" setting for an arbitrary application in macOS
#!/usr/bin/python
# Some notes about using this script:
# - Configure the application path and bundle id below
# - This script needs to be run as the user you need to set the checkmark for
# - The setting will not take effect until they log out and log back in at least once
import os.path
from Foundation import NSHomeDirectory, CFPreferencesCopyMultiple, CFPreferencesSetMultiple, kCFPreferencesAnyUser, kCFPreferencesCurrentHost, NSMutableDictionary, NSURL, NSURLBookmarkCreationMinimalBookmark, NSMutableArray
# --- CHANGE THESE SETTINGS ---
lowres_app_path = u'/Applications/TextEdit.app'
lowres_app_id = u'com.apple.TextEdit'
# -----------------------------
# create the bookmark data
app_url = NSURL.alloc().initFileURLWithPath_(lowres_app_path)
bookmark, error = app_url.bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error_(NSURLBookmarkCreationMinimalBookmark, [], None, None)
# check if the file exists already
ls_prefs = os.path.join(NSHomeDirectory(), u'Library/Preferences/com.apple.LaunchServices/com.apple.LaunchServices')
ls_prefs_plist = ls_prefs + u'.plist'
if os.path.isfile(ls_prefs_plist):
# read it in
current_prefs = CFPreferencesCopyMultiple(None, ls_prefs, kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
else:
# make a new dictionary
current_prefs = NSMutableDictionary()
# Get any existing key or a new blank dict if not present
magnified = current_prefs.get(u'LSHighResolutionModeIsMagnified', NSMutableDictionary())
magnified_editable = NSMutableDictionary.dictionaryWithDictionary_(magnified)
# Build our values
options = NSMutableArray.alloc().init()
options.append(bookmark)
# A value of 3 = enabled, value of 2 = disabled
options.append(3)
magnified_editable[lowres_app_id] = options
# Update the setting
update_dict = NSMutableDictionary()
update_dict[u'LSHighResolutionModeIsMagnified'] = magnified_editable
result = CFPreferencesSetMultiple(update_dict, None, ls_prefs, kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
@gsnedders
Copy link

@pudquick Hey! This looks exactly like what I've been looking for; any chance of you attaching a license to this?

@gingerbeardman
Copy link

gingerbeardman commented Aug 8, 2020

I used PlistBuddy in an Alfred workflow

example
/usr/libexec/PlistBuddy -c "Set :LSHighResolutionModeIsMagnified:org.openscad.OpenSCAD:1 3" ~/Library/Preferences/com.apple.LaunchServices/com.apple.LaunchServices.plist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment