BluetoothUtil

Letzte Änderung: 03.12.2016

Bluetooth läßt sich unter MacOS einfach ein- und ausschalten.

main.m

//
//  main.m
//  BluetoothUtil
//
//  Created by Thomas Thielemann on 24.11.16.
//  Copyright © 2016 Thomas Thielemann. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "bluetoothUtil-Bridging-Header.h"
#import <stdio.h>

void printHelp() {
    printf(
               "NAME" "\n"
               "\tBluetoothUtil -- get and set Bluetooth state" "\n"
               "\n"
               "SYNOPSIS" "\n"
               "\tBluetoothUtil COMMAND" "\n"
               "\n"
               "DESCRIPTION" "\n"
               "\tGet the current value of Bluetooth state or set a new value." "\n"
               "\n"
               "\tThe following commands are available:" "\n"
               "\n"
               "\ton        Enable" "\n"
               "\toff       Disable" "\n"
               "\ttoggle    Toggle between on and off" "\n"
               "\tprint     Read current value" "\n"
               "\n"
           );
}


int main(int argc, const char * argv[]) {

    if (argc != 2) {
        printHelp();
        return -1;
    }
    else {
        if (strcmp(argv[1], "on") == 0 ) {
            IOBluetoothPreferenceSetControllerPowerState(1);
        } else if (strcmp(argv[1], "off") == 0 ) {
            IOBluetoothPreferenceSetControllerPowerState(0);
        } else if (strcmp(argv[1], "toggle") == 0 ) {
            int toggled = IOBluetoothPreferenceGetControllerPowerState() * (-1) + 1;
            IOBluetoothPreferenceSetControllerPowerState(toggled);
        }
        else if (strcmp(argv[1], "print") == 0 ) {
            printf("%s\n", IOBluetoothPreferenceGetControllerPowerState() == 1 ? "on" : "off");
        }
        else {
            printHelp();
        }
    }

    return 0;
}

Es werden noch zwei Header-Dateien benötigt:

bluetoothaccess.m

//
//  bluetoothaccess.m
//  bluetoothUtil
//
//  Created by Thomas Thielemann on 15.11.16.
//  Copyright © 2016 Thomas Thielemann. All rights reserved.
//

#import <Foundation/Foundation.h>

bluetoothUtil-Bridging-Header.h

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

#import	<IOBluetooth/Bluetooth.h>

void IOBluetoothPreferenceSetControllerPowerState(int);
int IOBluetoothPreferenceGetControllerPowerState();




© 2003-2017 th-thielemann.de