Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
zarifpour authored Feb 17, 2023
0 parents commit 0dd554c
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 0 deletions.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
232 changes: 232 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bundleid</key>
<string>zarifpour.yousuggest</string>
<key>category</key>
<string>Internet</string>
<key>connections</key>
<dict>
<key>B2496DEF-C902-4D76-BD7C-DC86D9DB4C04</key>
<array>
<dict>
<key>destinationuid</key>
<string>882A5947-06A0-49ED-8443-D55F88AEF74A</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
</dict>
<key>createdby</key>
<string>Daniel Zarifpour</string>
<key>description</key>
<string>Get in-line You.com search suggestions</string>
<key>disabled</key>
<false/>
<key>name</key>
<string>You.com Suggest</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>browser</key>
<string></string>
<key>skipqueryencode</key>
<false/>
<key>skipvarencode</key>
<false/>
<key>spaces</key>
<string></string>
<key>url</key>
<string>https://you.com/search?q={query}</string>
</dict>
<key>type</key>
<string>alfred.workflow.action.openurl</string>
<key>uid</key>
<string>882A5947-06A0-49ED-8443-D55F88AEF74A</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<true/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>1</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>{var:search_keyword}</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Getting suggestions…</string>
<key>script</key>
<string>// Define a function to create Alfred items from an array of suggestion names
function makeItems(itemNames) {
return itemNames.map(name =&gt; {
// Each item has a unique ID, a title that matches the suggestion name, a subtitle that indicates the search term and the search engine, and an argument that contains the suggestion name
return {
"uid": name,
"title": name,
"subtitle": "Search “" + name + "” on you.com",
"arg": name
}
})
}
// Retrieve the previous search term and suggestions from Alfred's environment variables
const oldArg = $.NSProcessInfo.processInfo.environment.objectForKey("oldArg").js
const oldResults = $.NSProcessInfo.processInfo.environment.objectForKey("oldResults").js
// Define the main function that generates the list of suggestions for Alfred
function run(argv) {
// If the user did not type anything, return an empty list of suggestions
if (!argv[0]) {
return JSON.stringify({ "items": [] })
}
// If the user is currently typing, return the previous suggestions as well as the new ones from the current search
if (argv[0] !== oldArg) {
return JSON.stringify({
// Rerun the script in 0.1 seconds to guarantee that the top suggestion matches the current query
"rerun": 0.1,
// Skip the default knowledge results and show only the script's output
"skipknowledge": true,
// Store the previous suggestions and search term in the environment variables for later use
"variables": { "oldResults": oldResults, "oldArg": argv[0] },
// Combine the previous suggestions and new ones from the current search, remove duplicates, and generate Alfred items from them
"items": makeItems(argv.concat(oldResults?.split("\n").filter(line =&gt; line)))
})
}
// If the user is not currently typing, make a request to the you.com autocomplete API to retrieve new suggestions
const encodedQuery = encodeURIComponent(argv[0])
const queryURL = $.NSURL.URLWithString(`https://you.com/api/ac?q=${encodedQuery}`)
const requestData = $.NSData.dataWithContentsOfURL(queryURL);
const requestString = $.NSString.alloc.initWithDataEncoding(requestData, $.NSUTF8StringEncoding).js
const newResults = JSON.parse(requestString)[1].filter(result =&gt; result !== argv[0])
// Return the new suggestions as Alfred items, and store them along with the current search term in the environment variables for later use
return JSON.stringify({
// Skip the default knowledge results and show only the script's output
"skipknowledge": true,
// Store the new suggestions and search term in the environment variables for later use
"variables": { "oldResults": newResults.join("\n"), "oldArg": argv[0] },
// Generate Alfred items from the new suggestions
"items": makeItems(argv.concat(newResults))
})
}
</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Search You.com with suggestions</string>
<key>title</key>
<string>Search You.com</string>
<key>type</key>
<integer>7</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>B2496DEF-C902-4D76-BD7C-DC86D9DB4C04</string>
<key>version</key>
<integer>3</integer>
</dict>
</array>
<key>readme</key>
<string># Usage
Get in-line suggestions from [You.com](https://you.com)'s search results via the Search Keyword (default: `y`). Press &lt;kbd&gt;&lt;/kbd&gt; to open the search results page with the default web browser.
![you-workflow.png](/resources/you-workflow.png)
# Setup
1. Go to **Alfred Preferences**.
2. Open the **Workflows** tab.
3. Select **You.com Suggest**.
4. Click **Configure Workflow...** to set the Search Keyword.
# Credits
This workflow is inspired by the [Google Suggest](https://alfred.app/workflows/alfredapp/google-suggest/) by Vítor Galvão.
"This workflow was adapted with the help of ChatGPT, a large language model trained by OpenAI. ChatGPT provided guidance and support during the development process."
---
Adapted with ❤️ by [Daniel Zarifpour](https://links.dev/z).</string>
<key>uidata</key>
<dict>
<key>882A5947-06A0-49ED-8443-D55F88AEF74A</key>
<dict>
<key>xpos</key>
<real>315</real>
<key>ypos</key>
<real>230</real>
</dict>
<key>B2496DEF-C902-4D76-BD7C-DC86D9DB4C04</key>
<dict>
<key>xpos</key>
<real>125</real>
<key>ypos</key>
<real>230</real>
</dict>
</dict>
<key>userconfigurationconfig</key>
<array>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>y</string>
<key>placeholder</key>
<string></string>
<key>required</key>
<false/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string>Key to start You.com suggestions</string>
<key>label</key>
<string>Search Keyword</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>search_keyword</string>
</dict>
</array>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.0.0</string>
<key>webaddress</key>
<string>https://links.dev/z</string>
</dict>
</plist>
5 changes: 5 additions & 0 deletions prefs.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
Binary file added resources/you-workflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0dd554c

Please sign in to comment.