Open sheki opened 8 years ago
If there’s a simple way of integrating this to the current Event API, then perhaps. For example by using NSDistributedNotificationCenter
. (I personally haven’t used launchers, so I’m not that familiar how they interoperate between apps.) I would rather not add too much complexity to keep the project simple.
I've thought about the same thing, for example changing phoenix layouts and behaviour based on other system events than what is available, or generally passing any information to phoenix. This could be emulated somewhat through tasks (by polling) though.
Adding support for new system events is certainly possibly, if there’s a clear use case for it.
Could be implemented along with #53.
If anyone else is looking for a cheeky solution i have right now. Just set your phoenix script up with a hotkey, and then trigger the hotkey via osascript in the terminal
osascript -e 'tell application "System Events" to keystroke "l" using {command down, option down}'
can turn that into a bash alias if your want it even easier by adding this to your .zshrc or .bashrc
alias triggerPhoenixHotkey='osascript -e "tell application \"System Events\" to keystroke \"l\" using {command down, option down}"'
I have been playing with an PoC implementation of this, to be able to use phoenix as a backend for window/workspace management from Raycast and the terminal, inspired by iTerm2 and the RPC API it exposes.
By adding Bridge.enable() in my config, Phoenix sets up and starts listening on a unix socket, this gives access the full Phoenix API.
It's a bit of a hack, phoenix calls handleBridgeEvent
when there's a message on the socket:
function handleBridgeEvent(data: any) {
const start = perf.now()
try {
if (data.type === 'internal') {
handleInternalEvent(data)
return
}
if ('batch' in data) {
const results = data.batch.map((d: any) => handleCommand(d))
return JSON.stringify({
type: 'batch',
data: results,
__duration: perf.now() - start,
})
}
// Process the event data
if ('command' in data) {
return JSON.stringify(handleCommand(data))
}
} catch (e) {
console.log('Error handling global event', e)
return JSON.stringify({
error: 'Error handling global event',
debug: String(e),
})
}
if ('type' in data) {
return JSON.stringify({
rpcId: data.rpcId,
type: typeof data,
error: `${data.command} not found`,
})
}
return JSON.stringify({ type: typeof data, error: 'Invalid command' })
}
There's a few things to clear up before it's ready for a PR:
Happy to discuss and try out suggestions! I have been running this for a few months now and its really neat! I can now connect and use Phoenix apis from Raycast, listing windows, recently opened etc, combined with the iTerm2 api and some local LLMs, it can enable really cool stuff:
I would like to tirgger Phoenix events via and API / library.
This way I can trigger Phoenix actions via "Alfred" or some other tool instead of relying on keyboard shortcuts. ( I am bad at remembering).
Is this a valid feature request or out of scope for this project ? I can look into an implementation if there is consensus.