我不熟悉 applescript 语言,但可以在为 socket.io 实现库的语言之间使用
使用socket.io,您可以在应用程序之间进行操作,socket.io 就像一个 node.js EventEmitter(或 pubsub),客户端可以发送事件并实时订阅这些事件。
对于您的情况,您可以使用 node.js 创建一个 socket.io 服务器
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
io.on('connection', function(socket){
// Listens the 'control-hide' event
socket.on('control-hide', function () {
// Emit for all connected sockets, the node-webkit app knows hot to handle it
io.emit('hide');
});
// Listens the 'control-show' event
socket.on('control-show', function () {
// Emit for all connected sockets, the node-webkit app knows hot to handle it
io.emit('show');
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
并将socket.io client 添加到您的 node-webkit 应用程序
var socket = require('socket.io-client')('http://localhost:3000'); // I will assume that the server is in the same machine
socket.on('connect', function(){
console.log('connected');
});
// Listens the 'hide' event
socket.on('hide', function(){
// hide window
});
// Listens the 'show' event
socket.on('show', function(){
// show window
});
对于这个例子,我假设另一个 javascript 应用程序将控制“显示”和“隐藏”操作
var socket = require('socket.io-client')('http://localhost:3000'); // I will assume that the server is in the same machine
socket.on('connect', function(){
console.log('connected');
});
// sends a 'control-show' event to the server
function show() {
socket.emit('control-show');
}
// sends a 'control-hide' event to the server
function hide() {
socket.emit('control-hide');
}