Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
I am a developer newbie and I want when I check button when its on a on states to do this:
Code:
-(IBAction)Purge:(id)sender{
    
    NSString* path = [[NSBundle mainBundle] pathForResource:@"TurnOn 2d Dock" ofType:@"scpt"];
    NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary];
    NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
    [appleScript executeAndReturnError:nil];
    
    
}

when the check button is in off state i want it to do this :
Code:
   NSString* path = [[NSBundle mainBundle] pathForResource:@"TurnOff 2d Dock" ofType:@"scpt"];
    NSURL* url = [NSURL fileURLWithPath:path];NSDictionary* errors = [NSDictionary dictionary];
    NSAppleScript* appleScript = [[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
    [appleScript executeAndReturnError:nil];

how do i do this thanks in advance please I really want to make this app.
Also check out my software on: https://www.macupdate.com/developers/profile/
 
Last edited by a moderator:

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
if (switchOutlet.state == NSOnState) {
     // your on code here
} else {
    // your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
if (switchOutlet.on) {
     // your on code here
} else {
    // your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)
thanks! I am going to upload some snapshots
 

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
if (switchOutlet.state == NSOnState) {
     // your on code here
} else {
    // your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)

look at this i connected the button but...
 

Attachments

  • Screen Shot 2013-03-06 at 4.10.44 PM.png
    Screen Shot 2013-03-06 at 4.10.44 PM.png
    449.6 KB · Views: 125

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
if (switchOutlet.state == NSOnState) {
     // your on code here
} else {
    // your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)

How do i add the action to the checkbox?
 

Attachments

  • Screen Shot 2013-03-06 at 4.13.07 PM.png
    Screen Shot 2013-03-06 at 4.13.07 PM.png
    429.4 KB · Views: 113

DavidBlack

macrumors 6502a
Original poster
Jan 27, 2013
606
239
Somewhere In Apple's HQ ;)
Add an IBOutlet for your NSSwitchButton. Connect it to your NSSwitchButton. Add in a conditional statement,

Code:
if (switchOutlet.state == NSOnState) {
     // your on code here
} else {
    // your off code here
}

If any of those terms are unfamiliar, google them.

(I'm assuming you already know enough C/Obj-C to figure out your on code and off code yourself.)
Sorry about that I got it to work but I also want the app to remember what button the user selected when the app quits how do I do that? I really appreciate your help
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Sorry about that I got it to work but I also want the app to remember what button the user selected when the app quits how do I do that? I really appreciate your help

Xcode, Command-Shift-2, Documentation, search for "NSUserDefaults".
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.