iTunes and Screensavers 1.3 Sourcecode
Class myEvents
Inherits CarbonApplicationEventsMBS
// Properties
Protected Dim PSN as memoryBlock
// Event implementations
Sub ApplicationTerminated(ProcessSerial as memoryblock)
if psn<>nil and ProcessSerial<>nil then
if psn.Long(0)=ProcessSerial.long(0) and psn.Long(4)=ProcessSerial.Long(4) then
iTunesPlay
psn=nil
end if
end if
Exception e as RuntimeException
System.DebugLog e.message
End Sub
Sub ApplicationLaunched(ProcessSerial as memoryblock)
dim p as ProcessMBS
p=new ProcessMBS
p.GetProcess(ProcessSerial)
if p.Name="ScreenSaverEngine" then
if iTunesRunning then
if iTunesPlaying then
psn=ProcessSerial
iTunesStop
end if
end if
end if
Exception e as RuntimeException
System.DebugLog e.message
End Sub
// Methods
Sub iTunesStop()
dim a as AppleScriptMBS
dim s as String
s="tell application ""iTunes"" to pause"
a=new AppleScriptMBS
a.Compile s
a.Execute
// NO error checking as we can't display it!
Exception e as RuntimeException
System.DebugLog e.message
End Sub
Sub iTunesPlay()
dim a as AppleScriptMBS
dim s as String
s="tell application ""iTunes"" to play"
a=new AppleScriptMBS
a.Compile s
a.Execute
// NO error checking as we can't display it!
Exception e as RuntimeException
System.DebugLog e.message
End Sub
Function iTunesRunning() As boolean
dim p as ProcessMBS
p=new ProcessMBS
p.GetFirstProcess
do
if p.MacCreator="hook" or p.BundleID="com.apple.iTunes" then // iTunes
Return true
end if
loop until not p.GetNextProcess
Return false
Exception e as RuntimeException
System.DebugLog e.message
End Function
Function iTunesPlaying() As boolean
// Return true if iTunes is playing
dim a as AppleScriptMBS
dim s as String
s="tell application ""iTunes"" to return player state"
a=new AppleScriptMBS
a.Compile s
a.Execute
Return a.Result="playing"
// NO error checking as we can't display it!
Exception e as RuntimeException
System.DebugLog e.message
End Function
End Class
Class App
Inherits Application
// Properties
Protected Dim e as myEvents
// Event implementations
Sub Open()
RegisterPlugins
e=new myEvents
e.Listen
End Sub
Function UnhandledException(error As RuntimeException) As Boolean
System.DebugLog error.Message
quit
Return true
End Function
End Class
Links
MBS Realbasic Chart Plugins - Christians Software aus Nickenich