1

Is it possible to make my mac automatically open a website on safari the very first time it is woken up just once in a day?

So for example, I come to work at 8:30 and wake up / boot up my mac and Safari automatically opens up on a certain URL.

But then I go for lunch and turn it off / make it sleep and come back an hour later and this time nothing happens. And maybe i have a meeting and come back later and still nothing happens.

Until the next day this process repeats (only opening safari the very first time)

Sorry, i'm not sure how to even google for this.

I thought maybe "Automator" could do something like this but i think it requires me to manually click on it.

5
+50

It sounds like launchctl or crontab could come in handy here. I only know how to use crontab though.

Using crontab

  1. Get to a terminal (Press Command+SPACE then type Terminal and press Return)
  2. Type in EDITOR=nano crontab -e
  3. In this editor type @daily open -a safari http://<website to open to>
  4. Then press Control+X (do not press Command)
  5. At the confirmation press Y
  6. When typing the location to save to don't change anything just press Return

This should launch Safari the first time you log in each day.

Source of open -a safari <url>: https://superuser.com/a/459271/670755

|improve this answer|||||
2

There's two parts to this.

Firstly, running an application once in a day. I've written this in bash on linux, had someone test this. Credit where credit is due I pulled in part of this answer for invoking safari in bash

As always you'll need to tweak the bash script to your precise needs, and this probably ought to be set to hardcode a complete path or run in a specific folder for neatness. As is, the script This is a minimal, workable example though. I suspect the specific syntax of the open command may need tweaking, and you may want to completely hardcode the path of the lockfiles to be completely safe.

!/bin/bash
daydate=x`date +%j`

if [ -f $daydate.lockfile ];
then
        echo "task already run"
else
        rm *.lockfile; open -a safari http://www.example.com ;touch $daydate.lockfile
fi

In english - it uses the date command and creates a environmental variable with the current day of year prefixed with an x. On first run, it'll not find the file its looking for, attempt to clear out the lockfile (and fail, since its not there), opens safari and creates a file called xddd.lockfile. As such, unless you run this exactly a year apart, it should work.

On every other run, it'll check for a lockfile with the current day of year. If it exists, it'll echo "task already run" (you can set this to do nothing I suppose). Else, it'll clear out previous lockfiles, open safari to example.com and create a lockfile. You could in theory have a more unique identifier than the day number (date and year?) but this works well enough.

You'd then want to run this on login. I've not tested this bit yet, and I suspect there's some more elegant way to do it.

This SO answer suggests a few ways to launch this bash file on login. The 'simplest' way I can see is using automator - borrowed from mklement0's answer

  • File > New, type Application
  • Add a Run Shell Script action, which adds an embedded bash script, and either paste your script code there or add a command that invokes an existing script from there.
  • Save the *.app bundle and add it to the Login Items list in System Preferences > User & Groups > Login Items.

Add the bash script here and it should check each time you login and do its magic.

|improve this answer|||||
1

Yes it is possible !

Pick safari from your dock

If safari is already in your dock—either as a permanent fixture or because the app is in use—right click (or hold Control and click) on the icon. If the app isn’t in use, you’ll see a menu with three items. If the app is in use, the steps are the same, but you’ll see a few more menu options. Click Options, and then select Open at Login.

set a url open in the startup of safari

Open Safari, then choose Safari > Preferences and click General. Adjust these settings:

New windows open with: Choose Homepage. Homepage: Enter the URL of the page that you want Safari to display when it opens. Or click Set to Current Page to use the URL of the page that's currently active.

|improve this answer|||||
  • 1
    how do you make sure its only the first time in the day tho? Otherwise, sounds plausible – Journeyman Geek Dec 3 '16 at 9:46
  • Hey, I see how your solution would work, but this means every new tab i open would be opened at this URL (which launches a pop up and other stuff) so it might be a bit inconvenient. I was looking for a solution more along the scripted type. – Pochi Dec 4 '16 at 13:13
0

OS X has no built-in triggers for running actions on sleep or wake, but there are several third-party solutions—see the answers to this question for several options (the question is a few years old, but some of the apps mentioned certainly still exist).

Once you have the ability to run a script on wake, one approach would be to check the timestamp of a hidden file that you create in the user's home directory. If the timestamp is today, do nothing. Otherwise, run your 'open url' action, then touch the hidden file to update its timestamp.

|improve this answer|||||
  • The OP is asking how to do an action the first time they login each day. There are lots of methods in macOS to do something daily (and if the computer is off when it tries to wait until it wakes). – timotree Dec 4 '16 at 15:38
  • Maybe, that's not how I read it. They don't say anything about logging in or out. They said they wanted it to happen "the very first time it is woken up each day", which to me includes 'even if I haven't logged out since yesterday'. – calum_b Dec 4 '16 at 16:42
  • You're right. I interpreted 'wake' as 'log in'. – timotree Dec 4 '16 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.