• 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: Detect when I start to work...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detect when I start to work...


  • Subject: Re: Detect when I start to work...
  • From: 2551phil <email@hidden>
  • Date: Fri, 24 Mar 2017 20:21:15 +0700

> On 23 Mar 2017, at 20:30, Jean-Christophe Helary <email@hidden> wrote:
>
> it looks like Applescript is not able to act on a wake.

As a proof-of-concept, you should be able to use this as a starting point:


###########################################################
-->> IMPORT STATEMENTS
###########################################################

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
use framework “AppKit"

###########################################################
-->> HANDLERS
###########################################################

on waitForWake()
	tell current application's NSWorkspace to set theWorkspace to sharedWorkspace()
	set notifCenter to theWorkspace's notificationCenter()
	notifCenter's addObserver:me selector:"didWakeFromSleep" |name|:(current application's NSWorkspaceDidWakeNotification) object:(missing value)
	return 0
end waitForWake

on didWakeFromSleep()
	display dialog "I'm awake, let's do something"
	my stopObservingWakes()
end didWakeFromSleep

on stopObservingWakes()
	tell current application's NSWorkspace to set theWorkspace to sharedWorkspace()
	set notifCenter to theWorkspace's notificationCenter()
	notifCenter's removeObserver:me ¬
		|name|:(current application's NSWorkspaceDidAwakeNotification) object:(missing value)
end stopObservingWakes

###########################################################
-->> COMMANDS
###########################################################

my stopObservingWakes()
my waitForWake()


#EOF


Best


Phil
@sqwarq


 _______________________________________________
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: Detect when I start to work...
      • From: Jean-Christophe Helary <email@hidden>
References: 
 >Detect when I start to work... (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: Re: Lists to XML ?
  • Next by Date: Re: Detect when I start to work...
  • Previous by thread: Re: Detect when I start to work...
  • Next by thread: Re: Detect when I start to work...
  • Index(es):
    • Date
    • Thread