-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shogun
committed
Sep 4, 2016
1 parent
400e4d9
commit 8f83b8f
Showing
12 changed files
with
119 additions
and
94 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Carthage | ||
Frameworks | ||
alfred-chrome |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
### 1.0.0 / 2013-10-13 | ||
### 2.0.0 / 2016-09-03 | ||
|
||
* Update for Alfred 3 | ||
* Rewritten in Swift to simplify (un)installation. | ||
|
||
### 1.0.0 / 2014-11-05 | ||
|
||
* Added install and uninstall commands. | ||
* Initial public version. | ||
|
||
### 0.0.2 / 2014-11-03 | ||
|
||
* Finetuned execution and added the workflow file. | ||
|
||
### 0.0.1 / 2014-11-02 | ||
|
||
* Initial version. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github "crossroadlabs/Regex" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
github "crossroadlabs/Result" "2.0.1" | ||
github "crossroadlabs/Boilerplate" "0.2.4" | ||
github "crossroadlabs/Regex" "0.8.0" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
SRCDIR=${CURDIR} | ||
|
||
alfred-chrome : alfred-chrome.swift frameworks | ||
xcrun -sdk macosx swiftc -F Carthage/Build/Mac/ alfred-chrome.swift && install_name_tool -add_rpath "@executable_path/Frameworks" alfred-chrome | ||
|
||
frameworks: | ||
rm -rf Frameworks && ln -s Carthage/Build/Mac Frameworks | ||
|
||
install: alfred-chrome | ||
cd ~/Library/Application\ Support/Alfred\ 3/Alfred.alfredpreferences/workflows/user.workflow.${WORKFLOW} && \ | ||
rm -rf alfred-chrome Frameworks/* && \ | ||
cp ${SRCDIR}/alfred-chrome . && mkdir -p Frameworks && cp -a ${SRCDIR}/Carthage/Build/Mac/*.framework Frameworks | ||
|
||
clean: | ||
rm -rf Frameworks alfred-chrome | ||
|
||
default: alfred-chrome |
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Foundation | ||
import AppKit | ||
import Regex | ||
|
||
// First of all, gather the query and check if Chrome Canary is requested | ||
let query = Process.arguments.dropFirst().joinWithSeparator(" ") | ||
let useCanary = NSProcessInfo.processInfo().environment["alfred_chrome_canary"] == "YES" | ||
let name = "Chrome\(useCanary ? " Canary" : "")" | ||
|
||
// Check if the browser is installed, otherwise nothing to do | ||
let application = NSWorkspace.sharedWorkspace().absolutePathForAppBundleWithIdentifier("com.google.Chrome\(useCanary ? ".canary" : "")") | ||
|
||
if application == nil { | ||
print("Google \(name) not installed. Doing nothing!") | ||
exit(0) | ||
} | ||
|
||
// Now scan the list of valid profiles for the browser | ||
let fsManager = NSFileManager.defaultManager() | ||
let base = "\(fsManager.URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)[0].path!)/Google/\(name)" | ||
|
||
let profiles = try fsManager.contentsOfDirectoryAtPath(base) | ||
.filter({ $0 != "System Profile" && $0 != "Guest Profile" && fsManager.fileExistsAtPath(base + "/\($0)/Preferences") }) | ||
.reduce([String: String]()) { accu, entry in | ||
guard | ||
let preferences = NSData(contentsOfFile: base + "/\(entry)/Preferences"), | ||
let profileInfo = try? NSJSONSerialization.JSONObjectWithData(preferences, options: NSJSONReadingOptions()) as! NSDictionary, | ||
let profile = profileInfo["profile"]!["name"] as? String | ||
else { | ||
return accu | ||
} | ||
|
||
var newAccu = accu // Needed since accu is let and var usage is deprecated in Swift 3 | ||
newAccu[profile] = entry | ||
return newAccu | ||
} | ||
|
||
// Parse the query | ||
guard | ||
let matcher = try? Regex(pattern: "^(as\\s+(.+?)\\s+)?((in\\s+)?incognito\\s+)?(\\S+)$"), | ||
let match = matcher.findFirst(in: query) | ||
else { | ||
exit(0) | ||
} | ||
|
||
// Prepare executable path and its arguments | ||
let executable = NSBundle(path: application!)!.executablePath! | ||
var arguments = [match.group(at: 5)!] | ||
|
||
if let user = match.group(at: 2), let path = profiles[user] { | ||
arguments.append("--profile-directory=\(path)") | ||
} | ||
|
||
if match.group(at: 3) != nil { | ||
arguments.append("--incognito") | ||
} | ||
|
||
// Finally Launch the browser | ||
print("Launching: \(executable) \(arguments.joinWithSeparator(" "))") | ||
NSTask.launchedTaskWithLaunchPath(executable, arguments: arguments) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.