[
  {
    "path": "InputSourceSelector.m",
    "content": "// An utility to manipulate Input Sources.\n// Copyright (c) 2012 ARATA Mizuki\n#include <stdio.h>\n#include <stdlib.h>\n#include <Carbon/Carbon.h>\n#include <Foundation/Foundation.h>\nint main(int argc, char *argv[]) {\n    id pool = [NSAutoreleasePool new];\n    if (argc > 1 && (strcmp(argv[1],\"list\") == 0\n                     || strcmp(argv[1],\"list-enabled\") == 0)) {\n        Boolean listAll = strcmp(argv[1],\"list\") == 0;\n        NSArray *inputSources = [(NSArray *)TISCreateInputSourceList(NULL,listAll) autorelease];\n        for (NSObject *inputSource in inputSources) {\n            NSString *inputSourceID = TISGetInputSourceProperty((TISInputSourceRef)inputSource, kTISPropertyInputSourceID);\n            NSString *localizedName = TISGetInputSourceProperty((TISInputSourceRef)inputSource, kTISPropertyLocalizedName);\n            printf(\"%s (%s)\\n\",[inputSourceID UTF8String],[localizedName UTF8String]);\n        }\n    } else if (argc > 1 && (strcmp(argv[1],\"current\") == 0\n                            || strcmp(argv[1],\"current-layout\") == 0)) {\n        TISInputSourceRef inputSource\n            = strcmp(argv[1],\"current-layout\") == 0\n                ? TISCopyCurrentKeyboardLayoutInputSource()\n                : TISCopyCurrentKeyboardInputSource();\n        NSString *inputSourceID = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID);\n        NSString *localizedName = TISGetInputSourceProperty(inputSource, kTISPropertyLocalizedName);\n        printf(\"%s (%s)\\n\",[inputSourceID UTF8String],[localizedName UTF8String]);\n        CFRelease(inputSource);\n    } else if (argc > 2 && (strcmp(argv[1],\"enable\") == 0\n                            || strcmp(argv[1],\"disable\") == 0\n                            || strcmp(argv[1],\"select\") == 0\n                            || strcmp(argv[1],\"deselect\") == 0)) {\n        NSString *inputSourceID = [NSString stringWithUTF8String:argv[2]];\n        NSDictionary *properties = [NSDictionary dictionaryWithObject:inputSourceID\n                                                               forKey:(NSString *)kTISPropertyInputSourceID];\n        NSArray *inputSources = [(NSArray *)TISCreateInputSourceList((CFDictionaryRef)properties, true) autorelease];\n        if ([inputSources count] == 0) {\n            fprintf(stderr,\"Specified input source \\\"%s\\\" not found\\n\", argv[2]);\n            [pool release];\n            return 1;\n        }\n        TISInputSourceRef inputSource = (TISInputSourceRef)[inputSources objectAtIndex:0];\n        if (strcmp(argv[1],\"enable\") == 0) {\n            TISEnableInputSource(inputSource);\n        } else if (strcmp(argv[1],\"disable\") == 0) {\n            TISDisableInputSource(inputSource);\n        } else if (strcmp(argv[1],\"select\") == 0) {\n            TISSelectInputSource(inputSource);\n        } else if (strcmp(argv[1],\"deselect\") == 0) {\n            TISDeselectInputSource(inputSource);\n        }\n    } else {\n        const char usage[]\n          = \"Usage:\\n\"\n            \"   %s [command]\\n\\n\"\n            \"Available commands:\\n\"\n            \"   list                        Lists currently installed input sources.\\n\"\n            \"   list-enabled                Lists currently enabled input sources.\\n\"\n            \"   current                     Prints currently selected input source.\\n\"\n            \"   current-layout              Prints currently used keyboard layout.\\n\"\n            \"   enable [input source ID]    Enables specified input source.\\n\"\n            \"   disable [input source ID]   Disables specified input source.\\n\"\n            \"   select [input source ID]    Selects specified input source.\\n\"\n            \"   deselect [input source ID]  Deselects specified input source.\\n\";\n        fprintf(stderr,usage,argv[0]);\n    }\n    [pool release];\n    return 0;\n}\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "MIT License\n\nCopyright (c) 2012-2025 ARATA Mizuki\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "Makefile",
    "content": "all: InputSourceSelector\n\nInputSourceSelector: InputSourceSelector.m\n\t$(CC) -o $@ -Wall $< -framework Carbon -framework Foundation\n"
  },
  {
    "path": "README.md",
    "content": "InputSourceSelector\n===================\n\nA utility program to manipulate Input Sources on Mac OS X.\nThis program is a thin wrapper for [Text Input Sources Services API](https://developer.apple.com/library/mac/documentation/TextFonts/Reference/TextInputSourcesReference/).\n\nInstall\n=======\n\nTyping\n```\n$ make\n```\non the terminal should generate `InputSourceSelector` executable in the current directory.\nThen copy it to somewhere on `$PATH`.\n\nUsage\n=====\n\n```\n$ InputSourceSelector [command]\n```\n\n`[command]` is described below.\n\nCommands\n========\n\n* `list` Lists currently installed input sources.\n* `list-enabled` Lists currently enabled input sources.\n* `current` Prints currently selected input source.\n* `current-layout` Prints currently used keyboard layout.\n* `enable [input source ID]` Enables specified input source.\n* `disable [input source ID]` Disables specified input source.\n* `select [input source ID]` Selects specified input source.\n* `deselect [input source ID]` Deselects specified input source.\n\n`[input source ID]` is one of the input source IDs printed by `list`,`list-enabled`,`current`,`current-layout` commands,\nsuch as `com.apple.keylayout.US` or `com.apple.inputmethod.Kotoeri.Japanese`.\n\nExamples\n========\n\n* List all input sources installed on the system:\n```\n$ InputSourceSelector list\ncom.apple.keylayout.Czech-QWERTY (Czech - QWERTY)\ncom.apple.keylayout.Czech (Czech)\n...\ncom.apple.inputmethod.VietnameseIM.VietnameseVIQR (VIQR)\ncom.apple.inputmethod.VietnameseIM.VietnameseTelex (Telex)\n```\n\n* List currently enabled input sources on the system:\n```\n$ InputSourceSelector list-enabled\ncom.apple.keylayout.Dvorak (Dvorak)\ncom.apple.keylayout.US (U.S.)\n...\ncom.apple.KeyboardViewer (Keyboard Viewer)\ncom.apple.keylayout.UnicodeHexInput (Unicode Hex Input)\n```\n\n* Print the current input source:\n```\n$ InputSourceSelector current\ncom.apple.inputmethod.Kotoeri.Roman (Romaji)\n```\n\n* Print the current keyboard layout:\n```\n$ InputSourceSelector current-layout\ncom.apple.keylayout.Dvorak (Dvorak)\n```\n\nLicense\n=======\n\n[MIT License](LICENSE.txt)\n"
  }
]