Created
January 7, 2017 04:53
-
-
Save Watson1978/8208f5000e621a9a59dcba4cee93e5c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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