Answers:
保存这样的属性列表 ~/Library/LaunchAgents/com.superuser.457047.plist
(或者你改变标签的任何东西),并加载它 launchctl load ~/Library/LaunchAgents/com.superuser.457047.plist
或者退出并重新登录。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.superuser.457047</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>-e</string>
<string>tell application "System Events" to if (not (exists process "firefox")) or number of windows of process "firefox" is 0 then tell process "Finder" to click last menu item of menu 1 of menu bar 1</string>
</array>
<key>StartInterval</key>
<integer>5</integer> <!-- run every 5 seconds -->
</dict>
</plist>
在某些情况下,单击最后一个菜单项不起作用。 keystroke "q" using {option down, shift down, command down}
如果用户持有控制权将不起作用。
tell application "System Events" to log out
会显示一个确认对话框。
/System/Library/CoreServices/Menu\ Extras/user.menu/Contents/Resources/CGSession -suspend
不显示确认对话框但保持用户登录并显示快速用户切换屏幕。