File tree 3 files changed +22
-8
lines changed
3 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ if(currentPlayerState == 'playing') {
12
12
13
13
var exampleMsg = 'iTunes is currently paused' ;
14
14
console . log ( exampleMsg )
15
- } else { // If iTunes is not playing or paused, we assume that he is stopped
15
+ } else if ( currentPlayerState == " not running" ) {
16
16
17
- var exampleMsg = "iTunes is not playing at the moment." ;
17
+ var exampleMsg = "iTunes is not running at the moment." ;
18
18
console . log ( exampleMsg ) ;
19
- }
19
+ }
Original file line number Diff line number Diff line change 4
4
5
5
var applescript = require ( 'run-applescript' ) ;
6
6
var secToMin = require ( 'sec-to-min' ) ; // This is required for the duration of the track as iTunes returns the duration in seconds.
7
+ var { execSync } = require ( 'child_process' ) ;
7
8
var exports = module . exports = { } ;
8
9
9
10
@@ -86,11 +87,10 @@ exports.getCurrentTrackElapsedSeconds = function() {
86
87
}
87
88
} ;
88
89
exports . getPlayerState = function ( ) {
89
- // TODO: Check if iTunes is launched as another check before the AppleScript one
90
- try {
90
+ if ( isAppRunning ( "iTunes" ) ) {
91
91
return applescript . sync ( 'tell application "iTunes" to get the player state' ) ;
92
- } catch ( err ) {
93
- return null ;
92
+ } else {
93
+ return "not running" ;
94
94
}
95
95
} ;
96
96
exports . getPlaylistCount = function ( ) {
@@ -108,3 +108,17 @@ exports.getCurrentTrackElapsedSeconds = function() {
108
108
return null ;
109
109
}
110
110
} ;
111
+
112
+
113
+
114
+
115
+
116
+ function isAppRunning ( app ) {
117
+ try {
118
+ execSync ( 'pgrep -x "' + app + '"' ) ;
119
+ return true ;
120
+ }
121
+ catch ( err ) {
122
+ return false ;
123
+ }
124
+ }
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " itunes-bridge" ,
3
- "version" : " 0.1.8 " ,
3
+ "version" : " 0.1.9 " ,
4
4
"description" : " A NodeJS package to control and get informations from iTunes through AppleScript" ,
5
5
"main" : " itunes-bridge.js" ,
6
6
"repository" : {
You can’t perform that action at this time.
0 commit comments