如题,
通过安装SleepWatcher2.2.1,通过自己修改脚本在唤醒时该程序执行杀掉bluetoothd进程执行进程重启,相当于把自己重启一次蓝牙的步骤自动化。
程序给你们下回来了,程序的说明文档也给你们翻译好了。你们去试吧。
翻译过的说明文档:
SleepWatcher ReadMe
SleepWatcher is a command line tool (daemon) that monitors sleep, wakeup and idleness of a Mac. It can be used to execute a Unix command when the Mac or the display of the Mac goes to sleep mode or wakes up, after a given time without user interaction or when the user resumes activity after a break or when the power supply of a Mac notebook is attached or detached. It also can send the Mac to sleep mode or retrieve the time since last user activity. SleepWatcher是一个命令行工具(守护进程),用于监控Mac的睡眠、唤醒和闲置。当Mac或Mac的显示屏进入睡眠模式或被唤醒时,在没有用户互动的情况下,或在用户休息后恢复活动时,或在Mac笔记本的电源被连接或分离时,它可以用来执行Unix命令。它还可以将Mac送入睡眠模式或检索自上次用户活动以来的时间。
A little bit knowledge of the Unix command line is required to benefit from this software. 要从这个软件中获益,需要有一点Unix命令行的知识。
The current version removes the installer packages and requires manual installation. This hopefully prevents people without sufficient Unix knowledge to install this software. When you don’t feel familiar with the following installation hints, you are probably not the target audience of this software. 目前的版本删除了安装程序包,需要手动安装。这希望能防止没有足够Unix知识的人安装这个软件。当你对下面的安装提示感到不熟悉时,你可能不是这个软件的目标用户。
Upgrade from Version 2.0.5 (or below) 从2.0.5版(或以下)升级说明(针对以前安装过旧版的用户)看清楚!!!!,新用户安装指南在下面!!
For the following steps, we assume that you have unpacked the SleepWatcher 2.2.1 download on your desktop, i. e. you have the folder ~/Desktop/sleepwatcher_2.2.1 with this ReadMe as ~/Desktop/sleepwatcher_2.2.1/ReadMe.rtf. 在下面的步骤中,我们假设你已经将SleepWatcher 2.2.1的下载文件解压在你的桌面上,也就是说,你有~/Desktop/sleepwatcher_2.2.1这个文件夹,其中的ReadMe为~/Desktop/sleepwatcher_2.2.1/ReadMe.rtf。
1. Kill the running daemon and remove the old startup item: 1. 杀死正在运行的守护程序,并删除旧的启动项。注意仅限于已经安装过旧版sleepwatcher的用户,命令如下:
$ sudo killall sleepwatcher $ sudo rm -rf /Library/StartupItems/SleepWatcher
2. Copy the new binary and man page: 2. 复制新的二进制文件和手册页。命令如下
$ sudo cp ~/Desktop/sleepwatcher_2.2.1/sleepwatcher /usr/local/sbin $ sudo cp ~/Desktop/sleepwatcher_2.2.1/sleepwatcher.8 /usr/local/share/man/man8
3. Copy the launchd agent configuration and the updated rc scripts (when you have modified them, compare your version and the new one and update them as required): 3. 复制 launchd 代理配置和更新的 rc 脚本(当你修改了它们之后,比较你的版本和新的版本,并根据需要更新它们)。
$ sudo cp ~/Desktop/sleepwatcher_2.2.1/config/de.bernhard-baehr.sleepwatcher-20compatibility.plist /Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher.plist $ sudo cp ~/Desktop/sleepwatcher_2.2.1/config/rc.* /etc
4. Load the launchd agent configuration, this starts the SleepWatcher daemon: 4. 加载 launchd 代理配置,这将启动 SleepWatcher 守护程序。
$ sudo launchctl load /Library/LaunchDaemons/de.bernhard-baehr.sleepwatcher.plist
Now SleepWatcher runs again in an environment that matches the version 2.0 environment: users of the Mac can create executable files .sleep and .wakeup in their home directories that are executed when the Mac goes to sleep mode or wakes up. When you reboot the Mac, SleepWatcher is started automatically via launchd. 现在SleepWatcher又在一个与2.0版本相匹配的环境中运行了:Mac的用户可以在他们的主目录中创建可执行文件.sleep和.wakeup,当Mac进入睡眠模式或醒来时执行。当你重新启动Mac时,SleepWatcher会通过launchd自动启动。
When you use SleepWatcher on a single user Mac and only want to execute your own .sleep and .wakeup scripts, it is suggested not to run SleepWatcher as a system wide daemon with root permissions, but to run your own instance of SleepWatcher. To achieve this, after performing the above steps 1 and 2, continue with step 5: 当你在单用户Mac上使用SleepWatcher,并且只想执行你自己的.sleep和.wakeup脚本时,建议不要把SleepWatcher作为具有root权限的系统范围内的守护程序运行,而是运行你自己的SleepWatcher实例。要做到这一点,在执行完上述第1和第2步后,继续执行第5步。
5. Remove the old global rc scripts: 5. 删除旧的全局rc脚本。
$ sudo rm -f /etc/rc.sleep /etc/rc.wakeup
6. Copy the launchd agent configuration for a local user instance of SleepWatcher: 6. 为SleepWatcher的本地用户实例复制launchd代理配置。
$ mkdir ~/Library/LaunchAgents $ cp ~/Desktop/sleepwatcher_2.2.1/config/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist
7. Load the local launchd agent configuration, this starts the SleepWatcher daemon with your user account: 7. 加载本地 launchd 代理配置,这将以你的用户账户启动 SleepWatcher 守护程序。
$ launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist
Now SleepWatcher runs as a user agent that is stopped when you log off from the Mac and that is restarted when you log in again. Note that you must run SleepWatcher as a user agent when you want to use the options -t -i or -b -r (execute a command after a given time of user inactivity or when the user resumes its activity after a break), because these options require the Mac OS X GUI running, and this is not the case when SleepWatcher is started as a system wide daemon while booting. 现在,SleepWatcher作为一个用户代理运行,当你从Mac上注销时就会停止,当你再次登录时就会重新启动。注意,当你想使用选项-t -i或-b -r(在用户不活动一段时间后或在用户休息后恢复活动时执行命令)时,你必须将SleepWatcher作为用户代理运行,因为这些选项需要Mac OS X GUI运行,而当SleepWatcher在启动时作为系统范围内的守护程序启动时就不是这样了。
Upgrade from Version 2.1 and later
For the following steps, we assume that you have unpacked the SleepWatcher 2.2.1 download on your desktop, i. e. you have the folder ~/Desktop/sleepwatcher_2.2.1 with this ReadMe as ~/Desktop/sleepwatcher_2.2.1/ReadMe.rtf. 在下面的步骤中,我们假设你已经将SleepWatcher 2.2.1的下载文件解压在你的桌面上,也就是说,你有~/Desktop/sleepwatcher_2.2.1这个文件夹,其中的ReadMe为~/Desktop/sleepwatcher_2.2.1/ReadMe.rtf。 1. Replace /usr/local/sbin/sleepwatcher and /usr/local/share/man/man8:
$ sudo cp ~/Desktop/sleepwatcher_2.2.1/sleepwatcher /usr/local/sbin $ sudo cp ~/Desktop/sleepwatcher_2.2.1/sleepwatcher.8 /usr/local/share/man/man8
2. Kill the running SleepWatcher processes and let launchd restart them:
$ sudo killall sleepwatcher
Installation for new SleepWatcher users 以前没安装过的用户安装步骤
When you never have used SleepWatcher before, the following steps are suggests, assuming that you have unpacked the SleepWatcher 2.2.1 download on your desktop, i. e. you have the folder ~/Desktop/sleepwatcher_2.2.1 with this ReadMe as ~/Desktop/sleepwatcher_2.2.1/ReadMe.rtf. 当你以前从未使用过SleepWatcher时,建议采取以下步骤,假设你已经将SleepWatcher 2.2.1的下载文件解压在桌面上,即你有~/Desktop/sleepwatcher_2.2.1这个文件夹,该ReadMe为~/Desktop/sleepwatcher_2.2.1/ReadMe.rtf。
1. Install the SleepWatcher software: 1. 安装SleepWatcher软件命令。
$ sudo mkdir -p /usr/local/sbin /usr/local/share/man/man8 $ sudo cp ~/Desktop/sleepwatcher_2.2.1/sleepwatcher /usr/local/sbin $ sudo cp ~/Desktop/sleepwatcher_2.2.1/sleepwatcher.8 /usr/local/share/man/man8
2. Read the man page and think about the features of SleepWatcher you want to use: 2. 阅读手册页,想想你想使用SleepWatcher的哪些功能。
$ man sleepwatcher
3. Write small shell scripts that perform the actions you want to trigger by SleepWacher and test them. 3. 编写小的shell脚本,执行你想由SleepWacher触发的动作,并测试它们。
4. Test your scripts in combination with SleepWatcher, started in the foreground in a Terminal window, e. g.: 4. 测试你的脚本与SleepWatcher的结合,在终端窗口的前台启动,例如:
$ /usr/local/sbin/sleepwatcher --verbose --sleep /path/to/your/sleepscript --wakeup /path/to/your/wakeupscript ...
5. Put your SleepWatcher command line into a launchd agent configuration file. As an example you can use one of the plists from ~/Desktop/sleepwatcher_2.2.1/config. For more information about launchd and its configuration, see the man pages for launchd and launchd.plist and http://developer.apple.com/macosx/launchd.html. 5. 把你的SleepWatcher命令行放到 launchd agent配置文件中。作为一个例子,你可以使用~/Desktop/sleepwatcher_2.2.1/config中的一个plist。有关 launchd 及其配置的更多信息,请参阅 launchd 和 launchd.plist 以及 http://developer.apple.com/macosx/launchd.html 的手册页面。
6. Copy your launchd agent configuration to /Library/LaunchDaemons or ~/Library/LaunchAgents, depending on whether you need a system wide daemon or a user agent. 6. 将你的 launchd 代理配置复制到 /Library/LaunchDaemons 或 ~/Library/LaunchAgents,这取决于你是需要一个系统范围的守护程序还是一个用户代理。
7. Load the launchd agent configuration using launchctl (see examples above and the launchctl man page). 7. 使用 launchctl 加载 launchd 代理配置(见上面的例子和 launchctl man 页)。
|