This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
protocol AXWindowArray { | |
static func getWindows(processIdentifier pid: pid_t) -> [AXUIElement] | |
static func getWindows(bundleIdentifier bid: String) -> [AXUIElement] | |
} | |
extension AXWindowArray { | |
static func getWindows(processIdentifier pid: pid_t) -> [AXUIElement] { | |
let elm = AXUIElementCreateApplication(pid).takeUnretainedValue() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Run executable. | |
- parameter command: path to an executable file. | |
- parameter withAdminPrivileges: execute with administrator privileges(sudo use case). defaut value is false. | |
- returns: standard output in one string or nil when executable error. | |
*/ | |
public func sh(command: String, withAdminPrivileges: Bool = false) -> String? { | |
guard let res = NSBundle.mainBundle().resourcePath else { | |
NSLog("Unexpected error while initializing resource path.") | |
return nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// ErrorType | |
public enum OSAScriptError: ErrorType { | |
case InitializingFromSource(source: String?) | |
case InitializingFromContents(error: NSDictionary) | |
case Executing(error: NSDictionary) | |
case Unknown | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript -l JavaScript | |
ObjC.import('Foundation') | |
const argv = $.NSProcessInfo.processInfo.arguments.js | |
argv.forEach(function(arg, idx) { | |
if( idx < 4 ) return | |
console.log( arg.js ) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: ユーザー定義に依存したプロトコル拡張例。依存部分の初期設定は拡張外の責務。 | |
protocol FooSpec { | |
var fizz : Int { get } | |
func buzz() -> Int | |
} | |
extension FooSpec { | |
func buzz() -> Int { | |
return fizz * 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Non C-Style for statement | |
var i = 0; while (i < 10) { | |
console.log(`${i}`) | |
if ((i * i) % 2 == 0) { | |
i += 1 | |
} else { | |
i += 2 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ osascript -l JavaScript objc-sandbox.js | |
objc-sandbox.js:0:23: execution error: Error on line 1: Error: protocol does not exist (-2700) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run(argv) { | |
$.NSLog('%@', JSON.stringify(argv)) | |
return argv | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjC.import('Foundation') | |
ObjC.import('Carbon') | |
function virtualTyping(source) { | |
if (!source) { | |
throw new Error('Missing source') | |
} | |
if (typeof source !== 'string' || source.trim().length === 0) { | |
throw new Error('Invalid source') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
OlderNewer