Re: Detect when I start to work...
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