Display appliance: The Revenge; or Scripting QuickTime Player

QuickTime PlayerIn previous posts, we’ve told launchd to watch a directory for changes and launch a Perl script when changes occur. This script will tell QuickTime Player what to do.

I have a web CGI that people can use to select which QuickTime movie to display. This CGI then creates a symlink called “next.mov” that points to the selected movie. The Perl script looks for this file. Note that we don’t need QuickTime Pro in order to display the movie full-screen; AppleScript can tell QuickTime Player to go full-screen even without QuickTime Pro.

Here is a stripped-down version of the script I use:


#!/usr/bin/perl -w
 
use strict;
 
my $loggedInUser = `who | grep console`;
 
# directory in which we look for movies to play
my $mediapath = "/Users/Shared/DigitalWalkway/display";
 
if ($loggedInUser ne "") {
   # if there is a symlink at "$mediapath/next.mov" then
   # close the current movie and rename next.mov to current.mov
   if (-l "$mediapath/next.mov") {
      closeCurrentMovie();
      rename "$mediapath/next.mov", "$mediapath/current.mov";
   }
 
   # if there is a symlink at "$mediapath/current.mov" then
   # play it if its not already playing
   if (-l "$mediapath/current.mov" ) {
      # readlink gets the actual path of the file
      # that the symlink points to
      my $realpath = `readlink "$mediapath/current.mov"`;
      chomp $realpath;
 
      # basename strips off the path
      # and leaves just the filename
      my $realname = `basename "$realpath"`;
      chomp $realname;
 
      # we use osascript to embed an AppleScript into the Perl
      # script. in the AppleScript, we check to see if the
      # currently playing movie's name is the real name of
      # he current.mov link so we don't keep restarting
      # the same movie over and over
      `osascript<<EOF
tell application "QuickTime Player"
   activate
   set show welcome movie automatically to false
   copy "" to movieName
   if number of movies > 0 then
      copy (name of front movie) to movieName
   end if
   if (movieName is not "$realname") then
      open POSIX file "$mediapath/current.mov"
      set looping of movie 1 to true
      present movie 1 scale screen
   else
      if (display state of front movie is not presentation) then
         present front movie scale screen
      end if
      if (playing of front movie is false) then
         play front movie
      end if
   end if
end tell
EOF`;
   }
}
 
 
sub closeCurrentMovie {
   `osascript<<EOF
tell application "QuickTime Player"
   close every movie
end tell
EOF`;
   if (-l "$mediapath/current.mov" ) {
      unlink "$mediapath/current.mov";
   }
}

Display appliance: The Revenge; or Scripting QuickTime Player

2 thoughts on “Display appliance: The Revenge; or Scripting QuickTime Player

  1. Open Script Editor, then under the File menu, choose “”Open Dictionary…” and choose the application you’re interested in learning about.

Comments are closed.