Эх сурвалжийг харах

Do not activate Plex unless it is running.
Fully exit if the SILENCE leaves us.

Zachary Kotlarek 13 жил өмнө
parent
commit
82b08880ea
1 өөрчлөгдсөн 13 нэмэгдсэн , 3 устгасан
  1. 13 3
      dmx/qt_player.pl

+ 13 - 3
dmx/qt_player.pl

@@ -98,7 +98,7 @@ while (1) {
 
 	# Ensure "silence" is always available -- reset if it goes away
 	if (!exists($FILES{'SILENCE'})) {
-		init();
+		die("We need only the SILENCE\n");
 	}
 }
 
@@ -121,7 +121,7 @@ sub init() {
 	load('SILENCE', 'DMX/Silence.wav');
 
 	# Bring Plex back to the front
-	Audio::runApplescript('tell application "Plex" to activate');
+	activatePlex();
 }
 
 # Open the named file and record the handle
@@ -177,7 +177,7 @@ sub load($$) {
 	printFiles();
 
 	# Bring Plex back to the front
-	Audio::runApplescript('tell application "Plex" to activate');
+	activatePlex();
 }
 
 # Close the named file
@@ -216,3 +216,13 @@ sub printFiles() {
 	close($fh);
 	rename($tmp, $OUTPUT_FILE);
 }
+
+# Bring Plex to the front, if it's already running
+sub activatePlex() {
+	my @cmd = ('tell application "System Events"');
+	push(@cmd, 'if exists process "Plex" then');
+	push(@cmd, 'tell application "Plex" to activate');
+	push(@cmd, 'end if');
+	push(@cmd, 'end tell');	
+	Audio::runApplescript(join("\n", @cmd));
+}