-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display a list applications that can be used with sendkeys
Fixes #46
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
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,12 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"type": "shell", | ||
"command": "swift build" | ||
} | ||
] | ||
} |
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,59 @@ | ||
import ArgumentParser | ||
import Cocoa | ||
import Foundation | ||
|
||
class AppLister: ParsableCommand { | ||
public static let configuration = CommandConfiguration( | ||
commandName: "apps", | ||
abstract: | ||
"Lists apps that can be used with the send command." | ||
) | ||
|
||
struct AppInfo: Hashable { | ||
let name: String? | ||
let id: String? | ||
|
||
init(name: String?, id: String?) { | ||
self.name = name | ||
self.id = id | ||
} | ||
|
||
static func == (lhs: AppInfo, rhs: AppInfo) -> Bool { | ||
return lhs.name == rhs.name && lhs.id == rhs.id | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(self.name) | ||
hasher.combine(self.id) | ||
} | ||
} | ||
|
||
required init() { | ||
} | ||
|
||
func run() { | ||
let apps = Set( | ||
NSWorkspace.shared.runningApplications.filter { app in | ||
return app.activationPolicy == .regular | ||
} | ||
.map { app in | ||
return AppInfo(name: app.localizedName, id: app.bundleIdentifier) | ||
} | ||
) | ||
.sorted { a, b in | ||
return a.name?.lowercased() ?? "" < b.name?.lowercased() ?? "" | ||
} | ||
|
||
let maxLength = apps.reduce( | ||
0, | ||
{ max, info in | ||
return info.name?.count ?? 0 > max ? info.name!.count : max | ||
}) | ||
|
||
apps.forEach { info in | ||
print( | ||
"\((info.name ?? "-").padding(toLength: maxLength + 4, withPad: " ", startingAt: 0))id:\(info.id ?? "-")" | ||
) | ||
} | ||
} | ||
} |
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