Skip to content

Instantly share code, notes, and snippets.

@Watson1978
Created January 7, 2017 04:53
Show Gist options
  • Save Watson1978/8208f5000e621a9a59dcba4cee93e5c9 to your computer and use it in GitHub Desktop.
Save Watson1978/8208f5000e621a9a59dcba4cee93e5c9 to your computer and use it in GitHub Desktop.
// Add URL into safari's reading list
//
// Usage:
// swift readlinglist.swift http://apple.com
//
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate, NSSharingServiceDelegate {
func add(URL url : String) {
let service = NSSharingService(named: NSSharingServiceNameAddToSafariReadingList)!
service.delegate = self
let item = [NSURL(string: url)!]
service.perform(withItems: item)
}
public func sharingService(_ sharingService: NSSharingService, didShareItems items: [Any]) {
print("Succeeded")
exit(0)
}
public func sharingService(_ sharingService: NSSharingService, didFailToShareItems items: [Any], error: Error) {
print("Failed")
exit(1)
}
}
if CommandLine.argc < 2 {
exit(0)
}
var app = NSApplication.shared()
var delegate = AppDelegate()
delegate.add(URL: CommandLine.arguments[1])
app.delegate = delegate
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment