OSX/launchctl:如何每天早上在前台的新 chrome 实例中打开特定网站?

OSX/launchctl:如何每天早上在前台的新 chrome 实例中打开特定网站?

要求:

  1. 具体网站
  2. 每天早上,尽管笔记本电脑一夜之间关闭(launchctl 可以处理这个问题)
  3. 前台 - 必须引起我的注意,即使我有多个空间/桌面
  4. 新的 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 时出现任何怪癖,我会稍后更新。希望这不会成为问题。

相关内容