要求:
- 具體網站
- 每天早上,儘管筆記型電腦整夜關閉(launchctl 可以處理這個問題)
- 前景 - 必須引起我的注意,即使我有多個空間/桌面
- chrome 的新實例(不是必需的,但最好)
open http://superuser.com
當我在尚未打開 Chrome 的桌面/空間中嘗試時,我發現它在以下情況下失敗:3. 和 4.. 發生的情況是,在現有 Chrome 實例中打開一個選項卡其他空間/桌面靜靜地在後台。
答案1
這就是我的想法。比我想的簡單。
建立 shell 腳本 daily_goals.sh:
#!/bin/bash
# this is needed to launch Chrome as a new window. Since it's a new window, it will open in the foreground in current space/desktop.
open -n -a Google\ Chrome
# this sleeps for 1 second. It's necessary because otherwise the website, called below, will open in existing Chrome window, which may be located in another desktop. I think sleeping lets the next `open` call find the newly opened Chrome window, and replace the new tab with the provided website.
sleep 1
# the website I provided.
open http://joesgoals.com
創造/Library/LaunchDaemons/daily_goals.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>daily_goals</string>
<key>ProgramArguments</key>
<array>
<string>/Users/user/Work/daily_goals.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>07</integer>
<key>Minute</key>
<integer>00</integer>
</dict>
</dict>
</plist>
加入到launchctl:
launchctl load -w /Library/LaunchDaemons/daily_goals.plist
總而言之,這會在每天早上 7 點在新開啟的 Chrome 實例中啟動 joesgoals.com。如果筆記型電腦在早上 7 點處於睡眠狀態,則當筆記型電腦從睡眠狀態恢復時,它應該打開 JoesGoals。如果我在不同的桌面/空間(有或沒有 Chrome)中看到任何恢復 osx 的怪癖,我會稍後更新。希望這不會成為問題。