先来看下效果
昨天老大突然问我,能不能用OC做个自动登录App Store的mac软件,我说我这么牛逼当然可以.....半小时后就哭了,网上找相关资料发现真的少,也是第一次听说还有AppleScript这种脚本语言,然后网上看了些AppleScript代码,WTF,语法好流畅,简直是人跟机器的英语对话......
废话不多说,AppleScript代码奉上。附带github
property loginBtn : "登录…"
property logoutBtn : "注销"
on run {para1, para2}
tell application "App Store" to activate
tell application "System Events"
tell process "App Store"
set frontmost to true
try
click menu item loginBtn of menu "商店" of menu bar 1
on error
click menu item logoutBtn of menu "商店" of menu bar 1
delay 2
click menu item loginBtn of menu "商店" of menu bar 1
end try
delay 1
keystroke para1
keystroke tab
delay 1
keystroke para2
keystroke return
end tell
end tell
end run
这个搞定了,自动登录mac 软件的任意APP基本都会了把,记得给个喜欢😍