-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiTunesHook.applescript
27 lines (25 loc) · 996 Bytes
/
iTunesHook.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- This function returns true, if iTunes is running.
on iTunesRunning()
tell application "System Events" to (name of processes) contains "iTunes"
end iTunesRunning
(* Check if iTunes is running.
If iTunes is running, then run the itunescontroller python utility.
If no face is detected, then probably the mac user is detection, so pause playback.
If a face is detected, then mac user is in front of the screen, so now if the playback is paused then start playing. *)
if iTunesRunning() then
set detection to do shell script "/usr/local/bin/itunescontroller" as string
tell application "iTunes"
set playerState to player state as string
if detection contains "no face" then
if playerState is "playing" then
display notification "No user in front of mac. iTunes will be paused."
pause
end if
else
if playerState is "paused" or playerState is "stopped" then
display notification "Welcome back. iTunes will start playing."
play
end if
end if
end tell
end if