Skip to content

Instantly share code, notes, and snippets.

@ivan3bx
Created November 24, 2014 06:45
Show Gist options
  • Save ivan3bx/70e26e6b57e808a1b86c to your computer and use it in GitHub Desktop.
Save ivan3bx/70e26e6b57e808a1b86c to your computer and use it in GitHub Desktop.
NXOAuth2 handler using AppleScript to open Safari
func createAuthHandler() -> NXOAuth2PreparedAuthorizationURLHandler {
return { (url: NSURL!) -> Void in
let sourceScript = "tell application \"Safari\"\n"
+ " open location \"\(url.absoluteString!)\"\n"
+ " activate\n"
+ "end tell\n"
var err : NSDictionary?
let script = NSAppleScript(source: sourceScript)!
if script.compileAndReturnError(&err) {
if script.executeAndReturnError(&err) != nil {
//
// Success
//
} else {
println("Failed to execute and return")
}
} else {
println("Failed to compile script")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment