阿织的学习笔记 2019-06-28
在 iOS 12 发布以后,最好玩的功能莫属集成到系统的捷径,也就是之前的 workflow 了,配合 workflow 可以完成一连串的操作,在这里主要演示下在手机上通过 Siri 语音控制 Mac 完成办公环境的初始化。
最近又研究了下,发现可以更进一步,配合语音完成 Mac 的解锁并自动登录微信,解锁 Mac 需要在 App Store 购买 Unlox(当然如果你有 Apple Watch 的话当我没说)
打开 Mac 自带的脚本编辑器,输入一下代码:
-- active app on active(appName, isfull) if application appName is not running then tell application appName activate end tell if isfull is equal to 1 then fullScreen() end if if appName is equal to "iTerm" then initIterm() end if if appName is equal to "WeChat" then weChatLogin() end if end if end active -- init iTerm on initIterm() tell application "iTerm" tell current window create tab with default profile tell current tab tell application "System Events" keystroke "ssh user@ip" keystroke return delay 2 keystroke "password" keystroke return end tell end tell end tell end tell end initIterm -- full screen on fullScreen() delay 1 tell application "System Events" keystroke "f" using {control down, command down} end tell end fullScreen -- init samba connect on initSamba() tell application "Finder" open location "smb://user:password@ip" end tell end initSamba -- WeChat Login on weChatLogin() tell application "System Events" to tell process "WeChat" set frontmost to true click at {640, 440} end tell end WeChatLogin -- main initSamba() active("iTerm", 0) active("Mail", 0) active("DingTalk", 0) active("Visual Studio Code", 1) active("Google Chrome", 1) active("WeChat", 0)
说明:
/Users/username/Desktop/init.scpt
,此时可以直接运行这个脚本来验证程序是否 OK,运行过程中可能回需要允许一些辅助功能的权限url
, 选择第一个,把操作一复制的 schemes
添加到 url
下的输入框url
, 选择 打开url
ssh
,选择搜索出来的选项在密码下边的输入框中输入
osascript /Users/username/Desktop/init.scpt
大功告成!