• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Rebooting a Mac with a Mail Rule
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rebooting a Mac with a Mail Rule


  • Subject: Re: Rebooting a Mac with a Mail Rule
  • From: Bill Vlahos <email@hidden>
  • Date: Wed, 15 Mar 2017 17:44:09 -0700

Would it work if your AppleScript quit Mail first before issuing the restart command? I think that might mark the message as read.

Funny thing…as I was writing this reply, Mail crashed (10.12.3). It almost never does that.

Bill

On Mar 15, 2017, at 10:22 AM, Stockly, Ed <email@hidden> wrote:

Use a property to store the time of the reboot then test to see if the last reboot was within the last 10 minutes (or whatever time you think is reasonable).


Something like:

property lastReboot : ""
set rightNow to current date
if lastReboot is "" then
set lastReboot to rightNow
else if rightNow - lastReboot < 10 * minutes then
return
end if
set lastReboot to rightNow
do shell script "shutdown -r now"

 (I think there's also a shell command that will return the system uptime that you could use which would cover other reasons the mac restarted)



From: <applescript-users-bounces+ed.stockly=email@hidden> on behalf of debt <email@hidden>
Date: Wednesday, March 15, 2017 at 7:44 AM
To: AppleScript Digest <email@hidden>
Subject: Rebooting a Mac with a Mail Rule

I’ve written an AppleScript to restart a remote MacBook Pro using 

do shell script "shutdown -r now” ...

It works fine on it’s own, but I want to use it in a Mail rule so I can reboot the Mac remotely by sending it an email.  That’s where the problems start.

When the email comes in, the Mac reboots like it should.  But then when Mail reopens, it checks for mail again and then reboots again.  Now it’s in some kind of endless loop, and if I don’t disable the Mail rule, it will just keep rebooting.

This is on an older MacBook Pro running 10.6.8.  The rule also marks the message as read and moves it to the trash.

It “appears” that the email isn’t fully received before the reboot is triggered.  After the reboot happens a couple of times, and I disable the rule, then that email comes in completely.

Does anyone know what I need to do to get this to work?  I know about setting up a schedule with cron or launchd, but I’d also like to get this to work, as well.

Thanks,
Marc
Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users This email sent to email@hidden
  • Follow-Ups:
    • Re: Rebooting a Mac with a Mail Rule
      • From: Brian Christmas <email@hidden>
References: 
 >Rebooting a Mac with a Mail Rule (From: debt <email@hidden>)
 >Re: Rebooting a Mac with a Mail Rule (From: "Stockly, Ed" <email@hidden>)

  • Prev by Date: Re: Rebooting a Mac with a Mail Rule
  • Next by Date: Re: Rebooting a Mac with a Mail Rule
  • Previous by thread: Re: Rebooting a Mac with a Mail Rule
  • Next by thread: Re: Rebooting a Mac with a Mail Rule
  • Index(es):
    • Date
    • Thread