Skip to content

Commit 55b1a96

Browse files
jesse-cthomaspaulmann
authored andcommitted
Add script command: Define a word using the built-in dictionary/dicionaries
1 parent 0d2cd1e commit 55b1a96

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

commands/system/define-word.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/swift
2+
3+
// Required parameters:
4+
// @raycast.schemaVersion 1
5+
// @raycast.title Define Word
6+
// @raycast.author Jesse Claven
7+
// @raycast.authorURL https://github.com/jesse-c
8+
// @raycast.description Define a word using the built-in dictionary/dicionaries.
9+
// @raycast.packageName System
10+
// @raycast.mode fullOutput
11+
//
12+
// Optional parameters:
13+
// @raycast.icon 🗣
14+
// @raycast.argument1 { "type": "text", "placeholder": "Word (e.g. isthmus)" }
15+
16+
import Foundation
17+
18+
if CommandLine.argc != 2 {
19+
print("Must pass 1 word to define")
20+
} else {
21+
let argument = CommandLine.arguments[1].lowercased()
22+
23+
// https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/DictionaryServicesProgGuide/access/access.html#//apple_ref/doc/uid/TP40006152-CH5-SW3
24+
let result = DCSCopyTextDefinition(nil, argument as CFString, CFRangeMake(0, argument.count))?.takeRetainedValue() as String?
25+
26+
print(result ?? "No definition found")
27+
}

0 commit comments

Comments
 (0)