How would I make a checkbox hide the dock icon if it was checked? I have made a checkbox toggle a menubar item but how would you do it with the dock icon? Looking for some code to do this. Thanks!
i've use this code:
BOOL iconInDock = [[NSUserDefaults standardUserDefaults] boolForKey:smHideShowIcon];
if (iconInDock) {
ProcessSerialNumber psn = { 0, kCurrentProcess };
// display dock icon
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
ok, it's work for my application if I to set LSUIElement=1 in the Info.plist. That's code works only for show, but how I can hide icon?
Update for Swift, use both ways has been presented above (they give the same result):
public class func toggleDockIcon_Way1(showIcon state: Bool) -> Bool {
// Get transform state.
var transformState: ProcessApplicationTransformState
if state {
transformState = ProcessApplicationTransformState(kProcessTransformToForegroundApplication)
}
else {
transformState = ProcessApplicationTransformState(kProcessTransformToUIElementApplication)
}
// Show / hide dock icon.
var psn = ProcessSerialNumber(highLongOfPSN: 0, lowLongOfPSN: UInt32(kCurrentProcess))
let transformStatus: OSStatus = TransformProcessType(&psn, transformState)
return transformStatus == 0
}
public class func toggleDockIcon_Way2(showIcon state: Bool) -> Bool {
var result: Bool
if state {
result = NSApp.setActivationPolicy(NSApplicationActivationPolicy.Regular)
}
else {
result = NSApp.setActivationPolicy(NSApplicationActivationPolicy.Accessory)
}
return result
}
i've use this code:
BOOL iconInDock = [[NSUserDefaults standardUserDefaults] boolForKey:smHideShowIcon];
if (iconInDock) {
ProcessSerialNumber psn = { 0, kCurrentProcess };
// display dock icon
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
ok, it's work for my application if I to set LSUIElement=1 in the Info.plist. That's code works only for show, but how I can hide icon?
(Posting this as an answer because comments don't have code formatting)
QSBApplicationDelegate.m:223-228
BOOL iconInDock = [[NSUserDefaults standardUserDefaults] boolForKey:kQSBIconInDockKey];
if (iconInDock) {
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
}
You would want to set up your application as LSUIElement, and then use TransformProcessType to enable the Dock icon. The app will need to be relaunched for the change to take effect. See the Google Quick Search Box project for an example.
Setup your application as an LSUIElement and then call:
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
on launch.
This works for the MAS too.
© 2022 - 2024 — McMap. All rights reserved.