-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spotify.applescript
63 lines (56 loc) · 1.41 KB
/
Spotify.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
on run (argv)
set cmd to item 1 of argv
if is_running("Spotify") then
try
if cmd is equal to "current" then
current_track()
else if cmd is equal to "play" then
play()
else if cmd is equal to "pause" then
pause()
else if cmd is equal to "playpause" then
playpause()
else if cmd is equal to "next" then
next_track()
else if cmd is equal to "previous" then
previous_track()
end if
on error
log "Could not execute the command. Did you run the script from command line and passed in a valid argument? E.g. next, previous, play, pause or playpause?"
end try
end if
end run
on current_track()
tell application "Spotify"
if player state is equal to playing then
set artist_name to artist of current track
set track_name to name of current track
return artist_name & " - " & track_name
end if
end tell
end current_track
on play()
tell application "Spotify" to play
end play
on pause()
tell application "Spotify" to pause
end pause
on playpause()
tell application "Spotify" to playpause
end playpause
on next_track()
tell application "Spotify" to next track
end next_track
on previous_track()
tell application "Spotify"
if player position is greater than 3 then
previous track
previous track
else
previous track
end if
end tell
end previous_track
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running