Sample Script (DWS - Pause iTunes)

Top  Contents  Index 

This sample uses a COM object to communicate with iTunes and pause it.

 

 

/////////////////////////////////////////////////////////////////////////////

// Pause iTunes

// 

// Run once to Pause iTunes; run again to resume playing

//

// 01/20/2005 WTR - created

// 03/23/2005 WTR - cleaned up

/////////////////////////////////////////////////////////////////////////////

 

// LANGUAGE=DWS

 

/////////////////////////////////////////////////////////////////////////////

// COM CONSTANTS

/////////////////////////////////////////////////////////////////////////////

 

const S_OK = 0;

 

 

/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////

// CODE

/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////

 

procedure DebugMsg(s: String);

begin

  //ShowMessage(s);

  //LogActivity(s);

end;

 

 

var App: ComVariant;

 

App    := null;

 

DebugMsg('Initialized');

 

 

/////////////////////////////////////////////////////////////////////////////

// get application object

/////////////////////////////////////////////////////////////////////////////

try

  App := CreateOleObject('iTunes.Application');

  if VarIsNull(App) then

  begin

    ShowMessage('Could not access iTunes.  Please make sure it is installed properly.');

    Exit;

  end;

except

  on e: Exception do

  begin

    ShowMessage('Could not access iTunes.  Please make sure it is installed properly. (' +

      e.Message + ')');

    Exit;

  end;

end;

 

 

/////////////////////////////////////////////////////////////////////////////

// pause app

/////////////////////////////////////////////////////////////////////////////

try

  DebugMsg('About to pause');

  App.Pause();

finally

  DebugMsg('Cleaning up');

 

  // cleanup

  if not VarIsNull(App) then

    App := null;

end;