-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskipify.applescript
92 lines (76 loc) · 1.9 KB
/
skipify.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
set delaySec to 0.5
global currentUrl
global currentPos
global currentDur
set currentUrl to ""
set currentPos to 0
set currentDur to 0
repeat
local nextUrl
local nextPos
local nextDur
local shouldAlter
set nextUrl to nextUrl()
set nextPos to nextPos()
set nextDur to nextDur()
set shouldAlter to shouldAlter(nextUrl, nextPos)
if shouldAlter is true then
if currentUrl ≠ nextUrl then setPlayUrl(currentUrl)
setPlayPos(currentPos)
end if
if shouldAlter ≠ true then
set currentUrl to nextUrl
set currentPos to nextPos
set currentDur to nextDur
end if
delay delaySec
end repeat
on shouldAlter(nextUrl, nextPos)
if currentUrl ≠ "" and currentDur ≠ 0 then
if nextUrl ≠ currentUrl and currentPos < currentDur - 2 then
log "Skipped song"
return true
end if
end if
if nextUrl = currentUrl and nextPos ≠ 0 then
if nextPos < currentPos or nextPos > currentPos + 2 then
log "Skipped playhead"
return true
end if
end if
return false
end shouldAlter
on nextPos()
tell application "Spotify"
local var
set var to player position as real
return var
end tell
end nextPos
on nextUrl()
tell application "Spotify"
local var
set var to spotify url of current track as string
return var
end tell
end nextUrl
on nextDur()
tell application "Spotify"
local var
set var to duration of current track as string
return var / 1000
end tell
end nextDur
on setPlayPos(currentPos)
tell application "Spotify"
set player position to currentPos
end tell
end setPlayPos
on setPlayUrl(currentUrl)
tell application "Spotify"
play track currentUrl
end tell
end setPlayUrl
on setPlay()
tell application "Spotify" to play
end setPlay