首页 » 操作系统 » macOS » 正文

同步剪贴板内容 Hammerspoon

发布者:站点默认
2011/04/19 浏览数(1,103) 分类:macOS 同步剪贴板内容 Hammerspoon已关闭评论

sync.lua

按下 Shift+F9 时将选中内容复制后同步到服务端。Shift+F8 时将服务端的内容粘贴到光标位置。

Windows 版使用 AutoHotKey v1 实现

-- 远程剪贴板
hs.hotkey.bind(
  {'shift'},
  'f9',
  function()
    hs.eventtap.keyStroke({ "cmd" }, "c")
    local text = hs.pasteboard.readString()
    local url = 'https://upall.cn/pasteboard/'
    local headers = {
      ['Content-Type'] = 'x-www-form-urlencoded;charset=utf-8',
    }
    local code, body, headers = hs.http.post(url, text, headers)
    hs.alert.show("Pasteboard:" .. body)
  end
)
hs.hotkey.bind(
  {'shift'},
  'f8',
  function()
    local url = 'https://upall.cn/pasteboard/'
    local code, body, headers = hs.http.get(url)
    hs.pasteboard.setContents(body)
    hs.eventtap.keyStroke({ "cmd" }, "v")
  end
)

server

error_reporting(0);
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
  $data = file_get_contents("php://input");
  $data or exit();
  #file_put_contents('./plain.txt', "\n\n>>>>" . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
  #$r = file_put_contents('./plain.txt', $data, FILE_APPEND);
  $r = file_put_contents('./plain.txt', $data);
  echo $r; 
} else if ($method == 'GET') {
  echo file_get_contents('./plain.txt');
} else {
  exit("unknown mehtod: $method");
}                                                                                                                       
点击返回顶部
  1. 留言
  2. 联系方式