Mac Forums

Mac Forums (
-   OS X - Development and Darwin (
-   -   Desktop Switcher App Help! (

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?



//  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 {



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 06:09 AM.

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