问题
Is it possible to extend spotlight's search feature to support additional commands?
For example, is it possible to define custom web search aliases, meaning I could type yt and it would provide results from youtube.
Alternatively, is it possible to add additional system commands were I could type sl (or some variant) to put my computer to sleep.
回答1:
No it is not possible, there are only 4 types of extensions for OS X Yosemite:
Today - Get a quick update or perform a quick task in the Today view of Notification Center
Share - Post to a sharing website or share content with others
Action - Manipulate or view content within the context of another app
Finder - Present information about file sync states directly in Finder.
All of these extension types are explicitly activated by the user for functionality. Apple has said that they are just getting started with extensions and plan to add more in the future, so logically it seems that Spotlight extensions are next (goodbye Alfred :sadface:).
回答2:
In the meantime there is Flashlight (The missing plugin system for Spotlight) http://flashlight.nateparrott.com/
This is expandable with Python scripts.
UPDATE Oct 2016 It seems that Flashlight is not longer maintained. The last update was more then a year ago. Check the repo here: https://github.com/nate-parrott/Flashlight
UPDATE Mar 2017 There is a fork which is still maintained: github.com/w0lfschild/Flashlight – Thanks @amoebe
回答3:
I have an alternate solution for you which I am currently using. It's native to the OS and does not require disabling System Integrity Protection in order to install Flashlight.
Using Automator to create a new Service. Then with Ask For Text node you can display a popup similar to spotlight. From there the possibility are numerous. For web search there is a command like Display Webpages. The top activate
AppleScript command is for gaining focus of the following popup.
You can construct the URL from your input text using JavaScript node. You can parse "yt" to YouTube search url for example and put the rest after the space to the URL.
Then in Preference you can set this new service as a shortcut for easier access.
来源:https://stackoverflow.com/questions/25130549/os-x-yosemite-spotlight-extensions