-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotify-applescript-test.js
More file actions
62 lines (51 loc) · 1.43 KB
/
spotify-applescript-test.js
File metadata and controls
62 lines (51 loc) · 1.43 KB
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
// open at startup
// https://stackoverflow.com/questions/2564394/add-a-start-up-item-via-command-line-mac
// https://github.com/rogerwang/node-webkit/issues/1000
// some scripts:
// https://github.com/dronir/SpotifyControl/blob/master/SpotifyControl.scpt
// ok, often the getState or getTrack calls are often returning null, why??
// that's the child_process problem with node-webkit...
console.log('hi');
var spotify = require('spotify-node-applescript');
// Load native UI library
var gui = require('nw.gui');
// Create a tray icon
var tray = new gui.Tray({ icon: 'icon.png' });
// Give it a menu
var menu = new gui.Menu();
//menu.append(new gui.MenuItem({ type: 'checkbox', label: 'box1', checked: true }));
tray.menu = menu;
// Remove the tray
/*
tray.remove();
tray = null;
*/
// Bind a callback to item
var item = new gui.MenuItem({
label: "Click me",
click: function() {
console.log("I'm clicked");
spotify.playPause();
//getTrack();
}
});
menu.append(item);
function getTrack() {
spotify.getTrack(function(err, track) {
console.log(track);
if(track) {
tray.title = track.name + ' - ' + track.artist;
} else {
//tray.title = '';
}
});
}
function getState() {
spotify.getState(function(err, state) {
console.log(state);
});
}
//window.setInterval(getState, 5000);
window.setTimeout(function() {
window.setInterval(getTrack, 5000);
}, 2500);