|
Macos自动化神器hammerspoon
安装hammerspoon
下载安装- https://github.com/Hammerspoon/hammerspoon/releases
复制代码
在安装过程中遇到的问题,报错如下:
- Updating Homebrew...
- fatal: Could not resolve HEAD to a revision
- Error: Cask 'hammerspoon' is unavailable: No Cask with this name exists.
复制代码
brew 安装hammerspoon- brew install --cask hammerspoon
复制代码
下面分享一些lua
init.lua
- function open(name)
- return function()
- hs.application.launchOrFocus(name)
- if name == 'Finder' then
- hs.appfinder.appFromName(name):activate()
- end
- end
- end
- --- 快速程序如打开微信,Chrome,finder,QQ,把open("改成你需要的程序")
复制代码
gmail.lua
- local gmail = {}
- function gmail.mailCount(username, password, cb)
- local url = "https://mail.google.com/mail/feed/atom"
- hs.http.asyncGet(url, {Authorization = "Basic " .. hs.base64.encode(username .. ":" .. password)}, function(status, body, headers)
- if status == 200 then
- local mailCount = string.match(body, "<fullcount>([0-9]*)")
- cb(tonumber(mailCount))
- else
- print("gmail call failed with status code: " .. status)
- print("Please log an issue with the below information to https://github.com/andrewhampton/dotfiles")
- print(hs.inspect.inspect(headers))
- print(body)
- cb(0)
- end
- end)
- end
- return gmail
复制代码
wifi连接到指定的wifi后静音- local workWifi = 'wifi name'
- local outputDeviceName = 'Built-in Output'
- hs.wifi.watcher.new(function()
- local currentWifi = hs.wifi.currentNetwork()
- local currentOutput = hs.audiodevice.current(false)
- if not currentWifi then return end
- if (currentWifi == workWifi and currentOutput.name == outputDeviceName) then
- hs.audiodevice.findDeviceByName(outputDeviceName):setOutputMuted(true)
- end
- end):start()
复制代码
|
|