Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   Desktop Switcher App Help! (http://www.mac-forums.com/forums/os-x-development-darwin/310566-desktop-switcher-app-help.html)

cosmiccraze6 04-16-2014 08:19 PM

Desktop Switcher App Help!
 
Hi All!
I have been creating a small status bar app that only runs in the status bar and allows you to switch between desktops (spaces)
My menu has buttons for space right and space left and I have connected them into the default AppDelegate.m and created an IBAction for them.
What piece of code allows me to either make theese buttons change the desktops on my mac, Or execute the control arrow keys key shortcut to change desktops?

Code:

//


//  AppDelegate.m

//  Window Switcher

//

//  Created by Dane Boulton on 16/04/2014.

//  Copyright (c) 2014 DaneBoultonCreations. All rights reserved.

//

#import "AppDelegate.h"


@implementation AppDelegate


@synthesize window=_window;


-(void)awakeFromNib {

    statusItem = [[NSStatusBar systemStatusBar]statusItemWithLength:NSVariableStatusItemLength ];

    [statusItem setMenu:menu];

    [statusItem setTitle:@"Space Switch"];

    [statusItem setHighlightMode: YES];

    [statusItem setImage:[NSImage imageNamed:@"image"]];

}

- (IBAction)helpWindow:(id)sender {

    [NSApp activateIgnoringOtherApps:YES];

    [_window makeKeyAndOrderFront:nil];

}

- (IBAction)quit:(id)sender {

    [NSApp terminate:nil];

}

- (IBAction)goleft:(id)sender {

    []
}

- (IBAction)goright:(id)sender {

    []
}

@end

What do I put under the IBAction go right and go left actions?
Thank you. If you need more information please let me know.

Mark FX 04-18-2014 02:02 PM

If you google sending keystroke in Objective-C, you'll see various listings, of which most are on Stack Oveflow.

They all look fairly cpmplex solutions using CFEventRef's.
You could also achieve the same results using Applescript with the NSAppleScript class object, or creating an ApplescriptObjC class in your Xcode project, and calling it from your Objective-C code.

Regards Mark


All times are GMT -4. The time now is 12:47 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.