Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 8ded238

Browse files
committed
delete hashbang as it prevents the cli from working (?)
1 parent a8182ca commit 8ded238

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed
33 Bytes
Binary file not shown.

SafariHistorySearch.playground/Contents.swift

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import Foundation
32

43
let HISTORY_PATH = "/Caches/Metadata/Safari/History"
@@ -11,10 +10,12 @@ struct HistoryItem {
1110
let plistURL: NSURL
1211

1312
init(fromPlistAtURL plistUrl: NSURL) {
13+
1414
func plistAt(url: NSURL) -> AnyObject {
1515
let data = NSData.init(contentsOfURL: url)
1616
return try! NSPropertyListSerialization.propertyListWithData(data!, options: .Immutable, format: nil)
1717
}
18+
1819
plistURL = plistUrl
1920
let plist = plistAt(plistUrl)
2021
if let urlString = plist.objectForKey("URL") as? String {
@@ -51,12 +52,11 @@ struct AlfredResult {
5152
text = url
5253
arg = historyItem.plistURL.path!
5354
icon = AlfredResult.SafariIconPath
54-
5555
}
5656

5757
func toXML() -> NSXMLElement {
5858
let resultXML = NSXMLElement(name: "item")
59-
resultXML.addAttribute(NSXMLNode.attributeWithName("uidid", stringValue: uid) as! NSXMLNode)
59+
resultXML.addAttribute(NSXMLNode.attributeWithName("uid", stringValue: uid) as! NSXMLNode)
6060
resultXML.addChild(NSXMLNode.elementWithName("arg", stringValue: arg) as! NSXMLNode)
6161
resultXML.addChild(NSXMLNode.elementWithName("title", stringValue: title) as! NSXMLNode)
6262
resultXML.addChild(NSXMLNode.elementWithName("subtitle", stringValue: sub) as! NSXMLNode)
@@ -67,7 +67,8 @@ struct AlfredResult {
6767
let largeTypeNode = NSXMLElement.elementWithName("text", stringValue: text)
6868
largeTypeNode.addAttribute(NSXMLNode.attributeWithName("type", stringValue: "largetype") as! NSXMLNode)
6969
resultXML.addChild(largeTypeNode as! NSXMLNode)
70-
return resultXML }
70+
return resultXML
71+
}
7172
}
7273

7374
var outputPipe = NSPipe()
@@ -88,10 +89,10 @@ func captureStandardOutput(task: NSTask) {
8889
let previousOutput = totalString ?? ""
8990
let nextOutput = previousOutput + "\n" + outputString
9091
totalString = nextOutput
91-
92-
let paths = totalString.componentsSeparatedByString("\n").filter({ component -> Bool in
92+
let paths = totalString.componentsSeparatedByString("\n").filter {
93+
component in
9394
return component != ""
94-
})
95+
}
9596
showItemsAtPaths(paths)
9697
})
9798
outputPipe.fileHandleForReading.waitForDataInBackgroundAndNotify()
@@ -111,19 +112,15 @@ func shell(args: [String]) -> Int32 {
111112
func showItemsAtPaths(paths: [String]) {
112113
var results = [AlfredResult]()
113114
let root = NSXMLElement(name: "items")
114-
115115
for path in paths {
116116
let item = HistoryItem(fromPlistAtURL: NSURL.fileURLWithPath(path))
117-
118117
guard let alfredResult = item.alfredResult() else {
119118
continue
120119
}
121-
122-
results.append(alfredResult)
123-
124120
let resultXML = alfredResult.toXML()
125121
root.addChild(resultXML)
126122

123+
results.append(alfredResult)
127124
if results.count >= MAX_RESULTS {
128125
break
129126
}
@@ -137,10 +134,9 @@ let fileManager = NSFileManager()
137134
let libraryURL = try! fileManager.URLForDirectory(.LibraryDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
138135
let fullPath = libraryURL.path!.stringByAppendingString(HISTORY_PATH)
139136
var mdfindArgs = ["mdfind", "-onlyin", fullPath]
140-
//let concattedArgs = Process.arguments.dropFirst()
141-
let concattedArgs = ["google"]
137+
let concattedArgs = Process.arguments.dropFirst()
142138
if let args = concattedArgs.first {
143139
let splittedArgs = args.componentsSeparatedByString(" ")
144140
mdfindArgs.appendContentsOf(splittedArgs)
145141
shell(mdfindArgs)
146-
}
142+
}

safariSearch

160 Bytes
Binary file not shown.

safariSearch.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env xcrun swift
2-
31
import Foundation
42

53
let HISTORY_PATH = "/Caches/Metadata/Safari/History"
@@ -58,7 +56,7 @@ struct AlfredResult {
5856

5957
func toXML() -> NSXMLElement {
6058
let resultXML = NSXMLElement(name: "item")
61-
resultXML.addAttribute(NSXMLNode.attributeWithName("uidid", stringValue: uid) as! NSXMLNode)
59+
resultXML.addAttribute(NSXMLNode.attributeWithName("uid", stringValue: uid) as! NSXMLNode)
6260
resultXML.addChild(NSXMLNode.elementWithName("arg", stringValue: arg) as! NSXMLNode)
6361
resultXML.addChild(NSXMLNode.elementWithName("title", stringValue: title) as! NSXMLNode)
6462
resultXML.addChild(NSXMLNode.elementWithName("subtitle", stringValue: sub) as! NSXMLNode)

0 commit comments

Comments
 (0)