I am trying to check TM menu so if “Back up now” visible click but if menu says “Skip this back up” it does nothing. I would prefer an Apple script answer but would be grateful for any help.
Thanks. Andrew
I am trying to check TM menu so if “Back up now” visible click but if menu says “Skip this back up” it does nothing. I would prefer an Apple script answer but would be grateful for any help.
Thanks. Andrew
I don’t know how to script the Time Machine menu bar item. Are you trying to script running Time Machine? You can tell if Time Machine is running by running
/usr/bin/tmutil currentphase
if it returns
BackupNotRunning
then Time Machine is, as you might have guessed, not running.
And if you want to run it right now you can use
/usr/bin/tmutil startbackup --auto
However, man tmutil
says that startbackup
will “Begin a backup if one is not already running” so you could just run /usr/bin/tmutil startbackup --auto
and know that if Time Machine is already running, it will not start again.
However, here's a script which will check if Time Machine is running, and if it is not running, will start it.
#!/bin/zsh -f
CURRENT=$(/usr/bin/tmutil currentphase)
if [[ "$CURRENT" != "BackupNotRunning" ]]
then
/usr/bin/tmutil startbackup --auto
fi
exit 0
Hope that helps. Let me know if you have questions.
Hi tjluoma
Thanks for your help and yes I only want it to continue the same back up if one is already running. I will try the script when I return home and let you know.
Andrew
Hi tjluoma
I initially tried your script in Terminator and nothing happened, so now stuck. Can you offer anymore help please.
Andrew
Well, that's not your fault…I got the logic wrong.
I used !=
("is not equal to") when I should have used ==
("is equal to").
Try this:
#!/bin/zsh -f
CURRENT=$(/usr/bin/tmutil currentphase)
if [[ "$CURRENT" == "BackupNotRunning" ]]
then
/usr/bin/tmutil startbackup --auto
fi
Note! The menu bar icon for Time Machine will not change right away, but if you either click on the menu bar icon or open the Time Machine pane in System Preferences, you should see that it has started up.
Hi tjluoma
Thanks for the quick reply but unfortunately still no joy. I have copied & pasted all your code into Terminal, then pressed return, am I doing this all correctly? Surprisingly terminal does not ask me for my password.
Andrew