-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add quick-contact-actions extension #26717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ShixAJ
wants to merge
3
commits into
raycast:main
Choose a base branch
from
ShixAJ:ext/quick-contact-actions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
|
|
||
| # Raycast specific files | ||
| raycast-env.d.ts | ||
| .raycast-swift-build | ||
| .swiftpm | ||
| compiled_raycast_swift | ||
| compiled_raycast_rust | ||
|
|
||
| # compiled Swift binary (rebuilt via prebuild) | ||
| assets/get-contacts | ||
|
|
||
| # misc | ||
| .DS_Store | ||
|
|
||
| # Claude Code | ||
| .claude/ | ||
| CLAUDE.md |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "printWidth": 120, | ||
| "singleQuote": false | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Quick Contact Actions Changelog | ||
|
|
||
| ## [Initial Version] - {PR_MERGE_DATE} | ||
|
|
||
| - Search contacts with custom scoring (name, phone digits, email) | ||
| - Quick actions: FaceTime Video/Audio, Phone, Message, Email | ||
| - Detail side panel with profile picture and organization name | ||
| - Circular photo (from Swift) or colored initials (SVG) in detail pane | ||
| - Favorites section with pin/unpin support | ||
| - Frequently contacted section (top 5) | ||
| - Phonebook-style alphabetical sections | ||
| - Open and edit contacts in Contacts.app via AppleScript | ||
| - Contact argument for quick launch (auto-navigate on unique match) | ||
| - Copy actions for name, phone, and email | ||
| - Keyboard shortcuts for all actions |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Quick Contact Actions | ||
|
|
||
| Search your macOS contacts and launch calls, messages, and emails instantly from Raycast. | ||
|
|
||
| ## Features | ||
|
|
||
| - **Spotlight-style search** with smart scoring — matches by name, phone digits, or email | ||
| - **Quick actions** — FaceTime Video/Audio, Phone Call, iMessage, Email | ||
| - **Detail panel** (⌘D) with profile picture, name, and organization | ||
| - **Favorites** (⌘⇧S) — pin contacts to the top | ||
| - **Frequently contacted** — your top 5 most-used contacts appear automatically | ||
| - **Open/Edit in Contacts** — jump straight to the contact in Contacts.app | ||
| - **Contact argument** — type `qca ana` to auto-navigate if there's a unique match | ||
|
|
||
| ## Keyboard Shortcuts | ||
|
|
||
| | Shortcut | Action | | ||
| |----------|--------| | ||
| | ⌘⇧F | FaceTime Video | | ||
| | ⌘⇧A | FaceTime Audio | | ||
| | ⌘⇧C | Call | | ||
| | ⌘M | Send Message | | ||
| | ⌘E | Send Email | | ||
| | ⌘O | Open in Contacts | | ||
| | ⌘⇧O | Edit in Contacts | | ||
| | ⌘D | Toggle Detail Panel | | ||
| | ⌘⇧S | Toggle Favorite | | ||
| | ⌘. | Copy Name | | ||
| | ⌘⇧. | Copy Phone Number | | ||
| | ⌘⇧E | Copy Email | | ||
|
|
||
| ## Permissions | ||
|
|
||
| - **Contacts** — required to read your contacts. macOS will prompt automatically on first use. | ||
| - **Accessibility** — required for "Edit in Contacts" (sends ⌘L keystroke to Contacts.app via System Events). macOS will prompt when first used. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 131 additions & 0 deletions
131
extensions/quick-contact-actions/assets/get-contacts.swift
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import Foundation | ||
| import Contacts | ||
| import CoreGraphics | ||
| import ImageIO | ||
|
|
||
| func makeCircularImage(from data: Data, size: Int) -> Data? { | ||
| let s = CGFloat(size) | ||
| guard let source = CGImageSourceCreateWithData(data as CFData, nil), | ||
| let cgImage = CGImageSourceCreateImageAtIndex(source, 0, nil), | ||
| let ctx = CGContext(data: nil, width: size, height: size, bitsPerComponent: 8, | ||
| bytesPerRow: 0, space: CGColorSpaceCreateDeviceRGB(), | ||
| bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { return nil } | ||
| let rect = CGRect(x: 0, y: 0, width: s, height: s) | ||
| ctx.addEllipse(in: rect) | ||
| ctx.clip() | ||
| ctx.draw(cgImage, in: rect) | ||
| guard let clipped = ctx.makeImage() else { return nil } | ||
| let outData = NSMutableData() | ||
| guard let destFinal = CGImageDestinationCreateWithData(outData, "public.png" as CFString, 1, nil) else { return nil } | ||
| CGImageDestinationAddImage(destFinal, clipped, nil) | ||
| guard CGImageDestinationFinalize(destFinal) else { return nil } | ||
| return outData as Data | ||
| } | ||
|
|
||
| // Handle open/edit mode — reveal contact in Contacts.app | ||
| if CommandLine.arguments.count > 2 && (CommandLine.arguments[1] == "--open" || CommandLine.arguments[1] == "--edit") { | ||
| let isEdit = CommandLine.arguments[1] == "--edit" | ||
| let contactId = CommandLine.arguments[2] | ||
| let openStore = CNContactStore() | ||
| do { | ||
| let keys = [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor] | ||
| let contact = try openStore.unifiedContact(withIdentifier: contactId, keysToFetch: keys) | ||
| let name = "\(contact.givenName) \(contact.familyName)".trimmingCharacters(in: .whitespaces) | ||
| let escaped = name.replacingOccurrences(of: "\"", with: "\\\"") | ||
| var script = "tell application \"Contacts\"\nset thePeople to every person whose name is \"\(escaped)\"\nif (count of thePeople) > 0 then\nset selection to item 1 of thePeople\nend if\nactivate\nend tell" | ||
| if isEdit { | ||
| script += "\ndelay 0.1\ntell application \"System Events\" to keystroke \"l\" using command down" | ||
| } | ||
| let proc = Process() | ||
| proc.executableURL = URL(fileURLWithPath: "/usr/bin/osascript") | ||
| proc.arguments = ["-e", script] | ||
| try proc.run() | ||
| proc.waitUntilExit() | ||
| } catch { | ||
| fputs("error: \(error.localizedDescription)\n", stderr) | ||
| exit(1) | ||
| } | ||
| exit(0) | ||
| } | ||
|
|
||
| // Image cache dir passed as first argument (environment.supportPath from Raycast) | ||
| let imageDir = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : NSTemporaryDirectory() | ||
| let imageDirURL = URL(fileURLWithPath: imageDir, isDirectory: true) | ||
| try? FileManager.default.createDirectory(at: imageDirURL, withIntermediateDirectories: true) | ||
|
|
||
| let store = CNContactStore() | ||
| let keysToFetch: [CNKeyDescriptor] = [ | ||
| CNContactIdentifierKey as CNKeyDescriptor, | ||
| CNContactGivenNameKey as CNKeyDescriptor, | ||
| CNContactFamilyNameKey as CNKeyDescriptor, | ||
| CNContactOrganizationNameKey as CNKeyDescriptor, | ||
| CNContactPhoneNumbersKey as CNKeyDescriptor, | ||
| CNContactEmailAddressesKey as CNKeyDescriptor, | ||
| CNContactImageDataAvailableKey as CNKeyDescriptor, | ||
| CNContactThumbnailImageDataKey as CNKeyDescriptor, | ||
| ] | ||
|
|
||
| let request = CNContactFetchRequest(keysToFetch: keysToFetch) | ||
| request.sortOrder = .givenName | ||
| var contacts: [[String: Any]] = [] | ||
|
|
||
| do { | ||
| try store.enumerateContacts(with: request) { contact, _ in | ||
| guard !contact.phoneNumbers.isEmpty || !contact.emailAddresses.isEmpty else { return } | ||
|
|
||
| let firstName = contact.givenName | ||
| let lastName = contact.familyName | ||
| let org = contact.organizationName | ||
| var name = "\(firstName) \(lastName)".trimmingCharacters(in: .whitespaces) | ||
| if name.isEmpty { name = org } | ||
| if name.isEmpty { return } | ||
|
|
||
| let phones = contact.phoneNumbers.map { labeled -> [String: String] in | ||
| let label = labeled.label.flatMap { CNLabeledValue<NSString>.localizedString(forLabel: $0) } ?? "Phone" | ||
| return ["label": label, "value": labeled.value.stringValue] | ||
| } | ||
|
|
||
| let emails = contact.emailAddresses.map { labeled -> [String: String] in | ||
| let label = labeled.label.flatMap { CNLabeledValue<NSString>.localizedString(forLabel: $0) } ?? "Email" | ||
| return ["label": label, "value": labeled.value as String] | ||
| } | ||
|
|
||
| var entry: [String: Any] = ["id": contact.identifier, "name": name, "phones": phones, "emails": emails] | ||
|
|
||
| // Include organization only when the contact has a real first/last name (org is supplementary) | ||
| if !firstName.isEmpty || !lastName.isEmpty, !org.isEmpty { | ||
| entry["organization"] = org | ||
| } | ||
|
|
||
| // Save thumbnail to disk and return the path | ||
| if contact.imageDataAvailable, let imageData = contact.thumbnailImageData { | ||
| let safeId = contact.identifier.replacingOccurrences(of: "/", with: "_").replacingOccurrences(of: ":", with: "_") | ||
| let imageURL = imageDirURL.appendingPathComponent("\(safeId).jpg") | ||
| if !FileManager.default.fileExists(atPath: imageURL.path) { | ||
| try? imageData.write(to: imageURL) | ||
| } | ||
| entry["imagePath"] = imageURL.path | ||
|
|
||
| // Circular crop for detail pane | ||
| let circleURL = imageDirURL.appendingPathComponent("\(safeId)_circle.png") | ||
| if !FileManager.default.fileExists(atPath: circleURL.path), | ||
| let circleData = makeCircularImage(from: imageData, size: 160) { | ||
| try? circleData.write(to: circleURL) | ||
| } | ||
| if FileManager.default.fileExists(atPath: circleURL.path) { | ||
| entry["circleImagePath"] = circleURL.path | ||
| } | ||
| } | ||
|
|
||
| contacts.append(entry) | ||
| } | ||
| } catch { | ||
| fputs("error: \(error.localizedDescription)\n", stderr) | ||
| exit(1) | ||
| } | ||
|
|
||
| if let data = try? JSONSerialization.data(withJSONObject: contacts), | ||
| let json = String(data: data, encoding: .utf8) | ||
| { | ||
| print(json) | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| const { defineConfig } = require("eslint/config"); | ||
| const raycastConfig = require("@raycast/eslint-config"); | ||
|
|
||
| module.exports = defineConfig([ | ||
| ...raycastConfig, | ||
| ]); |
Binary file added
BIN
+2.78 MB
extensions/quick-contact-actions/metadata/quick-contact-actions-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.13 MB
extensions/quick-contact-actions/metadata/quick-contact-actions-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.74 MB
extensions/quick-contact-actions/metadata/quick-contact-actions-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.72 MB
extensions/quick-contact-actions/metadata/quick-contact-actions-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Swift code escapes double quotes in the contact name before embedding it in the AppleScript string, but does not escape newline characters (
\n). A contact whosegivenNameorfamilyNamecontains a literal newline (whichCNContactStoredoes not prohibit) would break out of the AppleScript string and allow arbitrary AppleScript injection.At minimum, newlines should also be stripped or escaped:
Prompt To Fix With AI