-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-song.js
executable file
·37 lines (31 loc) · 1.13 KB
/
get-song.js
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
#!/usr/bin/osascript -l JavaScript
function run(argv) {
try {
if (Application('com.apple.Music').running()) {
var musicApp = Application('com.apple.Music');
if (musicApp.playerState() === 'playing') {
var track = musicApp.currentTrack;
return track.name() + ' ' + track.artist();
}
}
} catch (err) { /* user on pre-catalina */ }
try {
if (Application('com.apple.iTunes').running()) {
var itunes = Application('com.apple.iTunes');
if (itunes.playerState() === 'playing') {
var track = itunes.currentTrack;
return track.name() + ' ' + track.artist();
}
}
} catch (err) { /* user on catalina */ }
try {
if (Application('com.coppertino.Vox').running()) {
var vox = Application('com.coppertino.Vox');
if (vox.playerState() === 1) {
return vox.track() + ' ' + vox.artist();
}
}
} catch (err) { /* app may not be installed */ }
// Easy to add more applications here
return '';
}