OSX / launchctl: как мне каждое утро открывать конкретный сайт в новом экземпляре Chrome на переднем плане?

417
barrrista

Требования:

  1. Конкретный сайт
  2. Каждое утро, несмотря на то, что ноутбук был закрыт на ночь (launchctl может справиться с этим)
  3. Передний план - должен привлекать мое внимание, даже если у меня несколько мест / рабочих столов
  4. Новый экземпляр хрома (не обязательно, но предпочтительнее)

Когда я пробую open http://superuser.comна рабочем столе / в пространстве, где Chrome уже не открыт, я вижу, что он не работает, 3 и 4. Что происходит, когда вкладка открывается в существующем экземпляре Chrome в другом пространстве / рабочем столе незаметно в фон.

1
Пытаетесь получить этот фанатичный значок, а? ;) Insane 8 лет назад 1
Помимо того, что я поднял это на передний план, моя просьба не слишком сумасшедшая. Я просто хотел уточнить все свои требования заранее, чтобы было понятно. barrrista 8 лет назад 0

1 ответ на вопрос

0
barrrista

Here's what I came up with. Was simpler than I thought.

Create shell script 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 

Create /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> 

Add to launchctl:

launchctl load -w /Library/LaunchDaemons/daily_goals.plist

In summary, this launches joesgoals.com every morning at 7am in a newly opened Chrome instance. If the laptop is asleep at 7am, it should open JoesGoals when the laptop is resumed from sleep. I'll update later if I see any quirks resuming osx in different desktops/spaces (with or without Chrome). Hoping it won't be an issue.