I'm trying to add a button in my Preferences Bundle to open an URL in Safari (or in the Pref Bundle).
I'm looking this: https://github.com/hbang/NotiQuiet/blob/master/prefs/ADNQListController.m
But I don't understand the else, if eccc...
I want just a button (for example "My website") that open www.mywebsite.com
Thanks all!
Add the following dictionary to your preferences plist:
{
action = link;
cell = PSButtonCell;
label = "Google";
}
And the following method to your bundle:
- (void)link {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://www.google.com"]];
}
Related
I am Developing the zip extractor app in cocoa for which i'm using findersync to show context menu item. But, the problem is item is showing for every file i want to show only for .zip files so how do i do that .
Any Suggestion.
Thanks in Advance!
Consider adding a service instead. That will allow you to add your item for any file not just those in monitored folders. The plist entries for a service allow you to directly specify what file types are acceptable, i.e. Restrict the service to ZIP files
Try this
NSURL *selectedURL = FIFinderSyncController.defaultController.selectedItemURLs[0];
NSURL *fileURL = selectedURL.filePathURL;
if([fileURL.pathExtension isEqualToString:#"zip"]) {
NSMenu *menu = [[NSMenu alloc] initWithTitle:#""];
NSMenuItem *item = [menu addItemWithTitle:#"Hello" action:#selector(itemTarget:) keyEquivalent:#""];
item.target = self;
return menu;
}
Much like Safari, trying to implement a button that when clicked opens System Preferences > Extensions > Share Menu pane.
I have tried:
NSURL *URL = [NSURL URLWithString:#"x-apple.systempreferences:com.apple.preferences.extensions?Share_Menu"];
[[NSWorkspace sharedWorkspace] openURL:URL];
However it seems like that is not working on newer versions, any ideas?
You can use Scripting Bridge to do something like this:
SBSystemPreferencesApplication *systemPrefs =
[SBApplication applicationWithBundleIdentifier:#"com.apple.systempreferences"];
[systemPrefs activate];
SBElementArray *panes = [systemPrefs panes];
SBSystemPreferencesPane *notificationsPane = nil;
for (SBSystemPreferencesPane *pane in panes) {
if ([[pane id] isEqualToString:#"com.apple.preferences.extensions"]) {
notificationsPane = pane;
break;
}
}
[systemPrefs setCurrentPane:notificationsPane];
SBElementArray *anchors = [notificationsPane anchors];
for (SBSystemPreferencesAnchor *anchor in anchors) {
if ([anchor.name isEqualToString:#"Extensions"]) {
[anchor reveal];
}
}
Of course you need to add the ScriptingBridge framework to your project and a Scripting Bridge header file for system preferences. More details on how to use Scripting Bridge you can find in the developer documentation from Apple.
Hope this helps
Since macOS Ventura (13.0) you can call the URL
x-apple.systempreferences:com.apple.preferences.extensions?Sharing
Mountain Lion offers a built-in sharing button that reveals a menu of sharing services appropriate for the app:
How can I insert it in my app?
To add the share button on Mountain Lion:
1) Add a NSButton called, for example, shareButton.
2) Add the standard image for this button:
[shareButton setImage:[NSImage imageNamed:NSImageNameShareTemplate]];
[shareButton sendActionOn:NSLeftMouseDownMask];
3) Into the "on click action", present the NSSharingServicePicker:
NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:urls];
sharingServicePicker.delegate = self;
[sharingServicePicker showRelativeToRect:[sender bounds]
ofView:sender
preferredEdge:NSMinYEdge];
4) Eventually, implement the NSSharingServicePickerDelegate methods to customize the picker’s available services.
In Swift, I've used this:
extension NSSharingService {
class func shareContent ( content: [AnyObject], button: NSButton ) {
let sharingServicePicker = NSSharingServicePicker (items: content )
sharingServicePicker.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSRectEdge.MaxY)
}
}
Note that if you're trying to add this button via Interface Builder:
Select the button
Switch to Attributes inspector
Delete the button Title
Insert: NSShareTemplate as the Image name.
It doesn't look right to me in XCode, but works fine when run.
PS - This appears to be a case where you need to use the System Icon string value (NSShareTemplate) instead of the constant (NSImageNameShareTemplate).
I am developing an app in which the toolbar can be shown/hide by the user using a button. The problem is the following: If the user chooses to hide the toolbar and then enters the fullscreen mode, the toolbar is shown.
The user interface has been created programmatically (i.e. not using Interface Builder).
This is the toolbar creation in the app delegate:
mainToolbar = [[NSToolbar alloc] initWithIdentifier:MAIN_TOOLBAR];
[mainToolbar setAllowsUserCustomization:NO];
[mainToolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
[mainToolbar setDelegate:self];
[window setToolbar: mainToolbar];
These are the actions performed by the buttons:
-(void)hideToolbar {
editing = YES;
[mainToolbar setVisible:NO];
}
-(void)showToolbar {
editing = NO;
[mainToolbar setVisible:YES];
}
I have tried to fix it using window delegate methods but still the toolbar is shown when entering full screen mode regardless the value of editing.
- (void)windowDidEnterFullScreen:(NSNotification *)notification {
[mainToolbar setVisible:!editing];
}
- (void)windowDidExitFullScreen:(NSNotification *)notification {
[mainToolbar setVisible:!editing];
}
Many thanks in advance!
I could not find a way to maintain the hidden/shown state of the toolbar when the window goes full screen, but you can set the toolbar to always be hidden in full screen, and to animate in when the user goes to the top of the screen. In your window delegate, you can set NSApplicationPresentationOptions to return NSApplicationPresentationAutoHideToolbar in as one of the options. Mine looks like this:
- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
{
return (NSApplicationPresentationFullScreen |
NSApplicationPresentationHideDock |
NSApplicationPresentationAutoHideMenuBar |
NSApplicationPresentationAutoHideToolbar);
}
Here is the relevant documentation: https://developer.apple.com/library/mac/#documentation/General/Conceptual/MOSXAppProgrammingGuide/FullScreenApp/FullScreenApp.html
Within one of my views, there is a webview that I load in a html page locally. Within this page I have a link (href) that when pressed it opens a view within the application and not a with in the webview/current view.
For example I have a button on this page that if pressed opens another view, is there any way I can do the same within a webview using a normal link?, the code I use for this button is below so is there away to get the href link in the web view link to similar code to open my new view up??
The link in the webview is a normal See view ???
#import "anotherview.h"
.....
-(void)myhereflinkBtn:(id)sender{
anotherview *newviewPage = [[anotherviewhehffvv alloc] initWithNibName:nil bundle:nil];
[UIView transitionFromView:self.view
toView: newviewPage view
duration:1.0
options: (UIViewAnimationCurveEaseInOut | UIViewAnimationOptionTransitionCurlUp)
completion:^(BOOL finished){}];
}
I hope this make sense.
Well with a bit of looking and a fresh face this morning I have manged to get 90% of what I am after working:
Using this link as help CLICK HERE i have managed to get my xcode register my link press
- (BOOL)theWebView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
NSLog(#"LINK CLICKED:");
[webView stopLoading];
return YES;
}
return YES;
}
- (void)viewDidLoad
{
webView.delegate = self;
[super viewDidLoad];
}
Within the header file I also then added < UIWebViewDelegate >