objective c - How can I reload the com.apple.systemuiserver preferences into the SystemUIServer application? -
for mac osx application, have feature removes system clock in upper right hand corner of screen when button clicked. preferences control system menus displayed (including system clock) stored in ~/library/preferences/com.apple.systemuiserver.plist. able update relevant preferences in file remove system clock. however, systemuiserver application needs restarted new preferences can reloaded , clock can removed. here code have used restart systemuiserver.
nstask *killsystemuitask = [[nstask alloc] init]; nsmutablearray *args = [nsmutablearray array]; [args addobject:@"systemuiserver"]; [killsystemuitask setlaunchpath:@"/usr/bin/killall"]; [killsystemuitask setarguments:args]; [killsystemuitask launch];
when systemuiserver killed, osx automatically restarts it. above code works, removal of system clock not clean like. entire system bar removed second. can think of better way reload preferences systemuiserver? ideally, i'd removal of system clock clean clock display function in date & time preferences of system preferences application.
have considered trying drive pref pane using appleevents/osascript? while network prefs pane seems 1 built-out scriptability, can drive ui system events. easy enough prototype in applescript. here's came with:
tell application "system preferences" reveal pane "date & time" reveal anchor "clockpref" of pane "date & time" tell application "system events" tell tab group 1 of window 1 of process "system preferences" repeat cbindex 0 count of checkboxes tell checkbox cbindex if title contains "menu bar" click exit repeat end if end tell end repeat end tell end tell quit end tell
you can either use using nsapplescript object, or if you're feeling masochistic, can dive in minutia of figuring out right appleevents send. (i recommend former approach sanity, latter execute faster @ runtime.)
pros: easy.
cons: launches system preferences (which can seen bouncing in dock), requires "enable access assistive devices" enabled (like many other things)
hard if visually better or worse killing systemuiserver, it's certainly kinder other components might interacting systemuiserver.
as far getting rid of dock bounce, question on here mentions how things start without dock icon. can add in past, i've wrangled problem, , solution came was, @ high level, this:
- get unique/safe temp directory
- make hard-links mirror of entire bundle of app in question (
pax -rwl
this) - replace hard-linked info.plist real copy of info.plist
- edit copy per directions in other question. (note: there other options setting
nsuielement = true
here, leave exercise reader , google.) - use application temp directory
- delete temp directory.
this approach has proven quite robust me when trying drive 3rd party applications. i'm guessing might, in future, run problems system applications signed/sandboxed. (i.e. changing info.plist changes signature, may refuse run.) also, naturally, sandboxed app require specific entitlement or exception send appleevents @ all, guess true of killing system processes (if that's possible sandboxed app @ all.)
lastly, should file bug report apple requesting first-class api or scriptability if feel it's important.
Comments
Post a Comment