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

DavidBlack

macrumors 6502a
Original poster
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:
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.)
 
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
 
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: 177
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: 162
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
 
Xcode, Command-Shift-2, Documentation, search for "NSUserDefaults".

i will have to look at theses methods:
- standardUserDefaults
- boolForKey:
- setBool:forKey:
I just want guidance on how to set the check button to save its on or off state when the user quits the app. Thank you anyone can help me?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.